*Solved*SQL syntax error in search code

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
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

*Solved*SQL syntax error in search code

Post by mohson »

Can anyone see anything wrong with the sql syntax in this code keep getting error message, for example if I enter 'a' in the search box I get the error message
Error in query: You have an error in your SQL syntax near 'WHERE name LIKE 'a%'' at line 5

Code: Select all

foreach($HTTP_POST_VARS as $varname => $value)
        $formVars[$varname]=$value;

 $query = 	"SELECT 
		 name, organisation,website,stu_id
		 FROM studentwebsites ORDER BY organisation 

WHERE name LIKE '$formVars[name]%'";
Last edited by mohson on Tue Apr 19, 2005 8:25 am, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ORDER BY clauses come after WHERE clauses.
Post Reply