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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.