archive — 2008-09-23T08:25:12-04:00 — #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 — 2008-09-23T08:27:53-04:00 — #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 — 2008-09-23T08:35:49-04:00 — #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 — 2008-09-23T08:39:03-04:00 — #4
then something else is wrong
have you tested the update query outside of php?
archive — 2008-09-23T08:54:17-04:00 — #5
yeap! and works perfectly..
r937 — 2008-09-23T08:56:37-04:00 — #6
so you may have a php problem, yes?
want me to move the thread to the php forum?
archive — 2008-09-23T08:57:47-04:00 — #7
please! thank for your time man.
guido2004 — 2008-09-23T09:01:00-04:00 — #8
Post your php code please
archive — 2008-09-23T09:05:16-04:00 — #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 — 2008-09-23T09:10:41-04:00 — #10
Now isn't that stupid or what????
Just added below the query:
$result = mysql_query($query);
Man, I gotta take a break!
guido2004 — 2008-09-23T09:13:11-04:00 — #11
Btw, are you sure there isn't a $ missing in front of userLoginID?
$query="UPDATE users SET accessDate=NOW() WHERE loginID = $userLoginID ";
r937 — 2008-09-23T09:16:42-04:00 — #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 — 2008-09-23T09:25:11-04:00 — #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...