Hi all again!
I'm having this accessDate field and I want at special occassions to update it through a PHP script, with the current datetime (NOW in phpmyadmin).
the field is: datetime NULL default '0000-00-00 00:00:00'
the query below doesnot seem to work:
UPDATE users SET accessDate = NOW WHERE loginID = xxxxxxx
Any ideas? Thank you all!
you forgot the parentheses for NOW()
you might want to use CURRENT_TIMESTAMP instead (it is standard SQL, whereas NOW() is mysql's proprietary equivalenmt)
thanks for your immediate response!
I'm afraid that neither NOW() nor CURRENT_TIMESTAMP have any impact upon the field's value.
Could it be the fact that these are (My)SQL functions and cannot be executed when php sends the query? I have to admit i doubt that.. :goof:
then something else is wrong
have you tested the update query outside of php?
yeap! and works perfectly..
so you may have a php problem, yes?
want me to move the thread to the php forum?
please! thank for your time man.
Post your php code please
Here you go:
$query="UPDATE users SET accessDate=NOW() WHERE loginID = userLoginID ";
Note that this query has also been run with quotes around NOW().
Now isn't that stupid or what????
Just added below the query:
$result = mysql_query($query);
Man, I gotta take a break!
Btw, are you sure there isn't a $ missing in front of userLoginID?
$query="UPDATE users SET accessDate=NOW() WHERE loginID = $userLoginID ";
that would turn it into a string, and that woun't work
mysql has very "forgiving" syntax (some would call it what it is -- "wrong")
for example, if you compare a numeric column like an auto_increment to a specific string like '3' then mysql will silently convert that string to the number 3
however, that's as far as it goes, it will not convert 'NOW()' to a function call
oh sorry, there is a $ in the original script, i justforgot it when i edited the original ID to make it userLoginID. All in all i just didn't execute the query...
This topic is now closed. New replies are no longer allowed.