Jump to content

Inserting the current date/time while submitting the forum


atrocious

Recommended Posts

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)
?>

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?

 

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 :wtf:

 

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])."'");

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.