Hi, I need help correctly inserting and displaying the current date from a mysql table. Here is the code that I'm using: <?php include('connect.php'); $name = 'jose'; $date = date('F d, Y'); $insert = " INSERT INTO test VALUES ('', '$name', '$date') "; mysql_query($insert); $read = " SELECT * FROM test "; $result = mysql_query($read); while($row = mysql_fetch_assoc($result)){ echo $row['name'] . ' ' . $row['date'] . '<br />'; } ?> HTML: The table named 'test' has a field named 'name' and a field named 'date'. I am not able to correctly display the date. The date displays as '0000-00-00'. The field type for the date field is 'date'. Thanks
Change the 'date' field to int. Use the following code to insert : $name = 'jose'; $insert = "INSERT INTO test VALUES ('', '$name', UNIX_TIMESTAMP())"; mysql_query($insert); PHP: And the following code to display the table entries : $read = "SELECT * FROM test"; $result = mysql_query($read); while($row = mysql_fetch_assoc($result)){ echo $row['name'] . ' ' . date('F d, Y',$row['date']) . '<br />'; } PHP:
tvoodoo provides the best solution to you. You can also convert any date into Timestamp see time() function details on php.net.
Thanks for the help. I found out how to get the date using the mysql CURDATE() function. I also tried the methods which you guys showed and suggested and they also worked for me. Again thanks.