archive
September 23, 2008, 12:25pm
1
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!
r937
September 23, 2008, 12:27pm
2
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)
archive
September 23, 2008, 12:35pm
3
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:
r937
September 23, 2008, 12:39pm
4
then something else is wrong
have you tested the update query outside of php?
archive
September 23, 2008, 12:54pm
5
yeap! and works perfectly…
r937
September 23, 2008, 12:56pm
6
so you may have a php problem, yes?
want me to move the thread to the php forum?
archive
September 23, 2008, 12:57pm
7
please! thank for your time man.
Post your php code please
archive
September 23, 2008, 1:05pm
9
Here you go:
$query="UPDATE users SET accessDate=NOW() WHERE loginID = userLoginID ";
Note that this query has also been run with quotes around NOW().
archive
September 23, 2008, 1:10pm
10
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 ";
r937
September 23, 2008, 1:16pm
12
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
archive
September 23, 2008, 1:25pm
13
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…