Using two where clauses in an update query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

Using two where clauses in an update query

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Double check the spelling, and Case of user_id in the stories table, different versions of Mysql are picky.

Code: Select all

{$_SESSION[uid]}
Also try taking the quotes out of the Array, i can't recall what syntax is correct with {} Brackets.
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

Post by ayfine »

Zoxive wrote:Double check the spelling, and Case of user_id in the stories table, different versions of Mysql are picky.

Code: Select all

{$_SESSION[uid]}
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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

You changed your query.

Remove the 2nd "where".
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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?
ayfine
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 4:52 pm

Post 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. :oops:

It's all working now.

Thanks for the help everyone.
Post Reply