Page 1 of 1
Using two where clauses in an update query
Posted: Sun Oct 07, 2007 6:18 pm
by ayfine
I am currently working on a project that allows users to say when they are done with a certian type and change an entry in the table from incompleted, to u_completed.
I want to make sure that it is only for one type ($type), and only for that user ($_SESSION['uid']).
Is it possible to use two where clauses in an update? If so how do I?
My current code is this
Code: Select all
$sql = mysql_query("UPDATE stories set `action` ='u_completed' where `user_id`='{$_SESSION['uid']}' and `type`='$type'") or die(mysql_error());
And I get this error :
Unknown column 'user_id' in 'where clause'
Thanks in advance!
Cheers.
Posted: Sun Oct 07, 2007 6:37 pm
by Zoxive
Double check the spelling, and Case of
user_id in the
stories table, different versions of Mysql are picky.
Also try taking the quotes out of the Array, i can't recall what syntax is correct with {} Brackets.
Posted: Sun Oct 07, 2007 6:42 pm
by ayfine
Zoxive wrote:Double check the spelling, and Case of
user_id in the
stories table, different versions of Mysql are picky.
Also try taking the quotes out of the Array, i can't recall what syntax is correct with {} Brackets.
Hmm.
I checked the spelling and it is all correct. I also took the quotes out, but I still get the same error.
I also tried changing the query to
Code: Select all
$sql = mysql_query("UPDATE stories set `action` ='u_completed' where `user_id`='{$_SESSION[uid]}' and where `type`='$type'") or die(mysql_error());
and I get this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where `type`='digg'' at line 1
Posted: Sun Oct 07, 2007 6:57 pm
by Zoxive
You changed your query.
Remove the 2nd "where".
Posted: Sun Oct 07, 2007 7:03 pm
by superdezign
Firstly, I believe the correct syntax for the array *is* with the quotes like you originally had. Secondly, if MySQL says that the column doesn't exist, then there is no column 'user_id' in the 'stories' table. Are you sure that you are looking at the right table?
Posted: Sun Oct 07, 2007 7:09 pm
by ayfine
superdezign wrote:Firstly, I believe the correct syntax for the array *is* with the quotes like you originally had. Secondly, if MySQL says that the column doesn't exist, then there is no column 'user_id' in the 'stories' table. Are you sure that you are looking at the right table?
Wow. I feel so stupid right now. I was looking at the wrong table.
It's all working now.
Thanks for the help everyone.