Page 1 of 1

update query syntax

Posted: Wed Mar 02, 2005 9:19 pm
by nhan
hope anyone can help me on the syntax...

i will update a single row where the conditions are :
field 1 and field 2 have values and field 3 is empty i tried this code:

$query = "UPDATE tbl SET field3='$Today' WHERE userName = '$user' and data3 ='NULL'";

userName is field 2 and data3 should have the value of $today which is initially empty

i tried the one above but it doesnt insert the data... thanks so much!

Posted: Wed Mar 02, 2005 9:22 pm
by John Cartwright

Code: Select all

$query = "UPDATE `tbl` SET `field3` = '$Today' WHERE `userName` = '$user' AND `data3` IS NULL";
The proper syntax is IS NOT not = NULL

Posted: Wed Mar 02, 2005 9:30 pm
by nhan
thanks so much for the reply but i have already tried that one but it does not update the row, should the varilbles field3 username and data3 be enclosed with single quotes(')????

thanks again!

Posted: Wed Mar 02, 2005 9:39 pm
by feyd
no.. they should be surrounded by backticks:

` vs. '

update query syntax

Posted: Wed Mar 02, 2005 10:42 pm
by nhan
i have already figured out what is wrong thanks so much every body, there is a big difference in using "NULL" and with the plain old single quotes('')....

Posted: Thu Mar 03, 2005 4:54 am
by timvw
that NULL <> 'NULL' is obvious ;)

the unobvious one is this: NULL <> NULL is also true. (For an sql dbms there is a logical explanation.. but for a relational database it's imho bollocks.)