what's wrong with this SQL statement?

Associate
Joined
21 May 2003
Posts
1,008
Hi. i've got a mySQL ssdatabase and i'm using php to access it and run a website.

in one page there's an option to add a new chosen team, however a player is only allowed to choose teams he hasn't addded before.

The original SQL statement made by PHPMaker which works fine is:
Code:
$sSqlWrk = "SELECT `teamID`, `name` FROM `teams`";
$sSqlWrk .= " ORDER BY `teamID` Asc";

I simply added a where statement in between them:
Code:
$sSqlWrk = "SELECT `teamID`, `name` FROM `teams`";
$sSqlWrk .= "WHERE `teamID` NOT IN (SELECT `teamID` FROM `chosenteams` WHERE `playersID` = $x_playersID)";
$sSqlWrk .= " ORDER BY `teamID` Asc";

all the titles/column nams are correct. I feel it may be something to do with quotes. anyway here's the error it gives me:

Failed to execute queryYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 SQL:SELECT `teamID`, `name` FROM `teams` WHERE `teamID` NOT IN (SELECT `teamID` FROM `chosenteams` ORDER BY `teamID` Asc

there's no mistake, that's how the error is shown, there's the whole where statemend missing after "chosenteams".

I thought maybe the sql statement had to many characters on one line so i made the second line shorter:
Code:
$sSqlWrk = "SELECT `teamID`, `name` FROM `teams`";
$sSqlWrk .= "WHERE `teamID` NOT IN (SELECT `teamID` FROM `chosenteams`"; 
$sSqlWrk .= " WHERE `playersID` = $x_playersID)";
$sSqlWrk .= " ORDER BY `teamID` Asc";

and this actually changes the error message. now i get:

Failed to execute queryUnknown column 'Team1' in 'where clause' SQL:SELECT `teamID`, `name` FROM `teams`WHERE `teamID` NOT IN (SELECT `teamID` FROM `chosenteams` WHERE `playersID` LIKE Team1) ORDER BY `teamID` Asc

Team1 is simply the players ID of the person currently logged in. Why does it think it's a column?

any help is appreciated, or any guidance as to where i can learn this stufff a bit better. thanks.
 
Last edited:
ok well i can't regenerate the first error now, i can only regenerate the second one where it complains about not finding the column.

is it something to do with the quotation marks? i actualyl want it to look for Team1 as a value in the playersID column.
 
Back
Top Bottom