gpt4 book ai didi

php - 如何在用 PHP 提交表单时添加日期和时间?

转载 作者:太空宇宙 更新时间:2023-11-03 11:54:22 28 4
gpt4 key购买 nike

<分区>

我正在用 php 制作一个评论系统,它可以存储评论、电子邮件和用户名,但我还想在我的数据库中添加 2 个字段,名为 time - date 存储用户自动提交表单的日期和时间!我搜索了很多,但找不到任何关于此的有用文章。如果您知道该怎么做,请帮助我,我将不胜感激!

这是我的代码:

<form action='comment.php' method='POST'>
<span>
<input type='text' name='name' placeholder='Your Name'/>
<input type='email' name='email' placeholder='Email Address'/>
</span>
<textarea name='' name='comment' placeholder='Comment'></textarea>
<input name='submit' type='submit' value='Submit'></input>
<p><?php if(isset($errors['name1'])) echo $errors['name1']; ?></p>
<p><?php if(isset($errors['name2'])) echo $errors['name1']; ?></p>
<p><?php if(isset($errors['email1'])) echo $errors['name1']; ?></p>
<p><?php if(isset($errors['email2'])) echo $errors['name1']; ?></p>
<p><?php if(isset($errors['comment1'])) echo $errors['name1']; ?></p>
<p><?php if(isset($errors['comment2'])) echo $errors['name1']; ?></p>
</form>
<?php
$con = mysqli_connect("localhost","root","","ecommerce");
if (isset($_POST['submit'])){
$name = (isset($_POST['name']));
$email = (isset($_POST['email']));
$comment = (isset($_POST['comment']));

if (empty($name)){
$errors['name1'] = "<p style='color:red;font-family: BCompset, Arial, Helvetica, sans-serif;font-size:30px;float:right;'>Enter your name</p>";
}else{
$name_length = strlen($name);
if ($name_length > 2 ){
if (!empty($email)){
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors['email1'] = "<p style='color:red;font-family: BCompset, Arial, Helvetica, sans-serif;font-size:25px;float:right;'>Enter your email</p>";
}else{
if (empty($comment)){
$errors['comment1'] = "<p style='color:red;font-family: BCompset, Arial, Helvetica, sans-serif;font-size:25px;float:right;'>Write your comment</p>";
}else{
$comment_length = strlen($comment);
if ($comment_length < 5){
$errors['comment2'] = "<p style='color:red;font-family: BCompset, Arial, Helvetica, sans-serif;font-size:25px;float:right;'>Your comment must be more than 5 words</p>";
}
}
}
}else{
$errors['email2'] = "<p style='color:red;font-family: BCompset, Arial, Helvetica, sans-serif;font-size:25px;float:right;'>Enter your email</p>";
}
}else{
$errors['name2'] = "<p style='color:red;font-family: BCompset, Arial, Helvetica, sans-serif;font-size:30px;float:right;'>Your name must be more than 2 words/p>";
}
}

//check errors
if(count($errors) == 0)
{
$insert_comment = "insert into comments (email,name,comment) values ('$email','$name','$comment')";
$insert_comment = mysqli_query($con, $insert_comment);
}
}
?>

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com