I am making a comment system in php which can store comment ,email and name of the user but I also want to add 2 fields more on my database called time - date that store the date and the time when user submitted the form automatically! I have searched a lot but I couldn't find any useful article about this. If you can know how to do that please help me I would appreciate that!
Here's my code:
<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);
}
}
?>