JSHINER Posted March 5, 2007 Share Posted March 5, 2007 Hello, I currently have the following to insert a variable into a database: $zip = $db->escape($_POST['zip']); $db->query("INSERT INTO zip SET zips = '$zip'"); I would like to also add the date & time the submission was made. Any help would be much appreciated. Thanks ! Link to comment https://forums.phpfreaks.com/topic/41282-insert-server-date-time-into-database/ Share on other sites More sharing options...
flappy_warbucks Posted March 5, 2007 Share Posted March 5, 2007 there are several ways to do it. i would use the date class. $today = date("j/n/Y"); $time = date("g:i"); $zip = $db->escape($_POST['zip']); $db->query("INSERT INTO zip SET zips = '$zip' date_and_time=\"$today - $time\""); Link to comment https://forums.phpfreaks.com/topic/41282-insert-server-date-time-into-database/#findComment-200010 Share on other sites More sharing options...
JSHINER Posted March 5, 2007 Author Share Posted March 5, 2007 I get the following error: Notice: Error in database query. Query was [iNSERT INTO zip SET zips = '01845' date_and_time=5/3/2007 - 10:09] and the error returned was [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date_and_time="5/3/2007 - 10:09"' at line 1] in /home/daily125/public_html/php/Statsdb.php on line 141 Any ideas ? Link to comment https://forums.phpfreaks.com/topic/41282-insert-server-date-time-into-database/#findComment-200018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.