wwfc_barmy_army Posted October 26, 2007 Share Posted October 26, 2007 Hello. I have the following code: <?php $editedtext = $_POST['edittext']; if ($_POST['Submit']) { $query="UPDATE text SET textblock='$editedtext', lastedit=CURDATE() WHERE textid = 3"; mysql_query($query); echo "Record Updated"; } ?> I've trying to get it so the lastedit field gets set to the date when it was last edited, but it's not entering anything, where am i going wrong? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/74863-solved-getting-edit-date-into-database/ Share on other sites More sharing options...
kratsg Posted October 26, 2007 Share Posted October 26, 2007 time() function would work. <?php $editedtext = $_POST['edittext']; if ($_POST['Submit']) { $query=" UPDATE text SET textblock='$editedtext', lastedit='time()' WHERE textid = '3' "; mysql_query($query) or die("I'm sorry, we encountered an error with this query.".mysql_error()); echo "Record Updated"; //print $query; //if you echo out the query, people can see what you're doing } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74863-solved-getting-edit-date-into-database/#findComment-378508 Share on other sites More sharing options...
wwfc_barmy_army Posted October 26, 2007 Author Share Posted October 26, 2007 Still nothing ??? The field is setup as a date type field and is currently 0000-00-00 if that makes a difference? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/74863-solved-getting-edit-date-into-database/#findComment-378509 Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 <?php $editedtext = $_POST['edittext']; if ($_POST['Submit']) { $date = date("Y-m-d", time()); $query=" UPDATE text SET textblock='$editedtext', lastedit='$date' WHERE textid = '3' "; mysql_query($query) or die("I'm sorry, we encountered an error with this query.".mysql_error()); echo "Record Updated"; //print $query; //if you echo out the query, people can see what you're doing } ?> www.php.net/date use that with www.php.net/time to get the format you need. Quote Link to comment https://forums.phpfreaks.com/topic/74863-solved-getting-edit-date-into-database/#findComment-378602 Share on other sites More sharing options...
kratsg Posted October 26, 2007 Share Posted October 26, 2007 you don't need the date format on the field. Make it an int(20) instead. This way, you can set a timestamp in there, why? A unix timestamp contains every information about that particular time. Seconds, Minutes, Hours, Day, Month, Year, Day of Week, AM/PM, and different timezones' time. For the most part, a unix timestamp is the best to use for saving current time. Quote Link to comment https://forums.phpfreaks.com/topic/74863-solved-getting-edit-date-into-database/#findComment-378881 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.