Page 1 of 1

Another SQL syntax error!

Posted: Sun Apr 05, 2009 4:23 pm
by cap2cap10
Greetings php technorati. Ok, I know this is probably a simple syntax error, but please
enlighten me. Here is the code:

Code: Select all

[color=#4000BF]$query = "SELECT * FROM js_profile WHERE category ='$category', years_exp = '$years_exp',
    degree ='$degree', work_time ='$work_time', available ='$available' LIMIT 0, 2000 ";
    $result = mysql_query($query) or die(mysql_error());[/color]
Here is the 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 ' years_exp = '', degree ='', work_time ='', available ='' LIMIT 0, 2000' at line 1

:banghead: tired of staring at variables. Please advise!!

Thanks in advance!

Batoe

Re: Another SQL syntax error!

Posted: Sun Apr 05, 2009 5:06 pm
by alex.barylski
Just a guess but if $work_time is an integer there is no need to wrap in single quotes.

Re: Another SQL syntax error!

Posted: Sun Apr 05, 2009 6:06 pm
by jayshields
Use AND instead of commas for seperating up your WHERE clause.

Re: Another SQL syntax error!

Posted: Mon Apr 06, 2009 6:00 am
by susrisha

Code: Select all

 
$query = "SELECT * FROM js_profile WHERE category ='$category' AND years_exp = '$years_exp' AND
    degree ='$degree' AND work_time ='$work_time' AND available ='$available' LIMIT 0, 2000 ";
 

Re: Another SQL syntax error!

Posted: Mon Apr 06, 2009 6:50 am
by Apollo
jayshields wrote:Use AND instead of commas for seperating up your WHERE clause.
or OR ;)
cap2cap10 wrote: Here is the 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 ' years_exp = '', degree ='', work_time ='', available ='' LIMIT 0, 2000' at line 1
Since SQL reports the query as years_exp='' and degree='' etc, are you sure that $years_exp and $degree etc actually contain values? (the query itself would still be valid (besides the commas) with empty strings, but it's probably not what you intended)