Good day every one!
In general, my question is about time function in php/mysql, how i can save time in mysql database? for date I chosed “date type” in the database to save $date and i wrote this code in php:
$date=date("y-m-d");
and this is my whole code about that part:
<?php
include_once ("connection.php");
$name=$_POST['sent_by'];
$id=$_POST['hidden_id'];
$id2=$_POST['hidden_id2'];
$message=$_POST['message'];
$submit= $_POST['submit'];
$date=date("y-m-d");
$time=time('yyyy-mm-d hh:mm:ss');
if($submit){
$place="INSERT INTO comments VALUES('','$name','$message','$id','$id2','$date','$time')";
$run = mysql_query("$place");
die("Your message have been sent Successfully !! <a href='member.php'>click here to return to your page</a>");
}
?>
for time what function i have to use? and which type i have to choose in database?
please help me!
thanks and regards
My advice is that you use either a timestamp or datetime type rather than the date type since you want both the date and time component. A timestamp type has some special properties you need to be aware of, but if you have the option to utilize a timestamp then that’s preferable from a storage standpoint. See this for more information.
You also should simply let the database set the time when inserted, which can be done automatically with a timestamp or manually using NOW().
One way of doing this, based on your code would be to change your query to be:
Notice that you no longer want or need php to create a date variable. The value of your DATETIME or TIMESTAMP column will be set to the system time of the mysql database server.