atrocious Posted October 15, 2009 Share Posted October 15, 2009 What do I need to add below to update the current date/time? I have a field in the database called datetime. I tried to use Now() but its not working. <?php $con = mysql_connect("host" , "aaaaa" , "pw"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("aaaaa", $con); mysql_query("update application set comment='".mysql_real_escape_string($_POST[comment])."' where `name`='".mysql_real_escape_string($_POST[name])."'"); /*This is what I tried to add so that i can directly inject the current date/time*/ $sql="INSERT INTO application (datetime) VALUES(NOW())"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/ Share on other sites More sharing options...
PravinS Posted October 15, 2009 Share Posted October 15, 2009 You have not used mysql_query() function for insert query $sql= mysql_query("INSERT INTO application (datetime) VALUES (NOW())"); Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937213 Share on other sites More sharing options...
atrocious Posted October 15, 2009 Author Share Posted October 15, 2009 aight thanks let me try it. Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937215 Share on other sites More sharing options...
atrocious Posted October 15, 2009 Author Share Posted October 15, 2009 It does add the date and time but it adds it to the new field instead of adding it to the existing field. So what I have to do here is update rather then adding. How do you insert that "NOW()" inside the update thing? anyone? Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937227 Share on other sites More sharing options...
atrocious Posted October 15, 2009 Author Share Posted October 15, 2009 Ok I tried adding the code below. It does update what i want to but its not putting the actual date there but its adding the text "NOW()" in the field lol mysql_query("update application set comment='".mysql_real_escape_string($_POST[comment])."' where `IGN`='".mysql_real_escape_string($_POST[name])."'"); mysql_query("UPDATE application SET userdatetime = '(NOW())' where `name`='".mysql_real_escape_string($_POST[name])."'"); Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937242 Share on other sites More sharing options...
PravinS Posted October 15, 2009 Share Posted October 15, 2009 remove the (') single quotes, use only NOW() function. Also why are you using 2 different queries to update same table. You can do it in single update query. Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937245 Share on other sites More sharing options...
atrocious Posted October 15, 2009 Author Share Posted October 15, 2009 remove the (') single quotes, use only NOW() function. Also why are you using 2 different queries to update same table. You can do it in single update query. Thanks! Its working now after removing the quotes. I know I can use the single update but I tried to modify got random error. Hence I don't want to spend time messing with it so i created another one lol..... can you fix it? Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937249 Share on other sites More sharing options...
PravinS Posted October 15, 2009 Share Posted October 15, 2009 Use like this mysql_query("update application set comment='".mysql_real_escape_string($_POST[comment])."', userdatetime = NOW() where `IGN`='".mysql_real_escape_string($_POST[name])."'"); Quote Link to comment https://forums.phpfreaks.com/topic/177749-inserting-the-current-datetime-while-submitting-the-forum/#findComment-937261 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.