Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Wed Mar 02, 2005 9:19 pm
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!
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Mar 02, 2005 9:22 pm
Code: Select all
$query = "UPDATE `tbl` SET `field3` = '$Today' WHERE `userName` = '$user' AND `data3` IS NULL";
The proper syntax is IS NOT not = NULL
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Wed Mar 02, 2005 9:30 pm
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!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 02, 2005 9:39 pm
no.. they should be surrounded by backticks:
` vs. '
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Wed Mar 02, 2005 10:42 pm
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('')....
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Mar 03, 2005 4:54 am
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.)