codeboy89 Posted October 29, 2009 Share Posted October 29, 2009 I am currently using time() in the created_at entries, I would like to use CURDATE, but cannot get it to work. can anyone please fix this snippet. $update = mysql_query("UPDATE comments SET comment='".$comment."',created_at='".time()."' WHERE user_id=".$_SESSION['logged_id']); } else { $insert = mysql_query("INSERT INTO comments(`id`,`user_id`,`comment`,`created_at`) VALUES(0,".$_SESSION['logged_id'].",'".$comment."','".time()."')"); Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/ Share on other sites More sharing options...
codeboy89 Posted October 29, 2009 Author Share Posted October 29, 2009 i have the database setup for date, i am just not sure what to do for the code in this snippet, i keep getting errors using CURDATE() Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946737 Share on other sites More sharing options...
l0ve2hat3 Posted October 29, 2009 Share Posted October 29, 2009 on your table structure just change the `created_at` attribute to on update current time stamp. and it will automatically do it for you Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946740 Share on other sites More sharing options...
codeboy89 Posted October 29, 2009 Author Share Posted October 29, 2009 i changed it to DATETIME and it just shows up as 0000-00-00 00:00:00 Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946742 Share on other sites More sharing options...
l0ve2hat3 Posted October 29, 2009 Share Posted October 29, 2009 did you change the attribute to current timestamp? Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946745 Share on other sites More sharing options...
codeboy89 Posted October 29, 2009 Author Share Posted October 29, 2009 i have changed the attribute to everything in phpmyadmin and get nothing but zeros, so im sure i need change from time() to curdate() but i get errors, i am not sure how to change it correctly in the snippet Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946746 Share on other sites More sharing options...
l0ve2hat3 Posted October 29, 2009 Share Posted October 29, 2009 $update = mysql_query("UPDATE comments SET comment='".$comment."' WHERE user_id=".$_SESSION['logged_id']); } else { $insert = mysql_query("INSERT INTO comments(`id`,`user_id`,`comment`) VALUES(0,".$_SESSION['logged_id'].",'".$comment."')"); Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946749 Share on other sites More sharing options...
codeboy89 Posted October 29, 2009 Author Share Posted October 29, 2009 $update = mysql_query("UPDATE comments SET comment='".$comment."' WHERE user_id=".$_SESSION['logged_id']); } else { $insert = mysql_query("INSERT INTO comments(`id`,`user_id`,`comment`) VALUES(0,".$_SESSION['logged_id'].",'".$comment."')"); how will that work? Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946753 Share on other sites More sharing options...
l0ve2hat3 Posted October 29, 2009 Share Posted October 29, 2009 did you try it? if you have the attribute "on update current_timestamp" mysql will automatically update the field with the current time stamp Link to comment https://forums.phpfreaks.com/topic/179430-help-switching-to-date-format/#findComment-946761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.