Page 1 of 1

SQL Query Error

Posted: Mon Dec 11, 2006 7:22 am
by mohson
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Can anyone see anything word with thie query, I keep getting 
"Error in query: You have an error in your SQL syntax near 'WHERE....

Code: Select all

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

$query = "SELECT 
		 
o.org_id,o.web_url,
f.salutation,f.name,f.surname,f.organisation,
f.email,f.address,f.address1,
f.telephonefax,f.mobile,f.mscints,
f.mscactive,f.otheractivities,f.gradjobs,
f.ugproj,f.pdev,f.bcsmem,f.bcspds,f.teach,
f.acconsult,f.person_id,f.org_id 
	
FROM feedbackcontacts f LEFT JOIN organisations o 
ON o.org_id = f.org_id
ORDER BY name ASC 

WHERE name LIKE '$formVars[name]%'";


$result = mysql_query($query);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Dec 11, 2006 8:13 am
by aaronhall
The ORDER clause needs to be after the WHERE clause.

Here's the proper clause order for a SELECT statement in MySQL: http://dev.mysql.com/doc/refman/5.0/en/select.html

Posted: Mon Dec 11, 2006 8:14 am
by andym01480
Would you need to specify where name comes from for ORDER BY and WHERE?

Code: Select all

ORDER BY f.name ASC 

WHERE f.name LIKE '$formVars[name]%'";
EDIT obviously not from correct answer posted below at same time!!!!

Posted: Mon Dec 11, 2006 8:17 am
by aaronhall
Also, the second error you're going to get is that "name" is ambiguous - it needs to be qualified with a table name, like 'f.name' or 'o.name'