php / MySQL: You have an error in your SQL syntax error
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64
Rep:
php / MySQL: You have an error in your SQL syntax error
Hi,
Thank you for reading.
I'm getting an error in My Query for some reason
and can't pinpoint EXACTLY where in the statement.
Here is what I currently have that is generating
the error:
Code:
$query="SELECT * FROM directory WHERE active='1'
AND column='L' AND type='paid' ORDER BY sortorder ASC";
$result = mysql_query ($query) or die(mysql_error());
Here is the error:
Quote:
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 'column='L' AND type='paid' ORDER BY sortorder ASC' at line 2
I've tried all different combinations,
all to no avail.
I know that it's got to be something simple and
something that I'm just overlooking.
I can't see anything wrong with the statement, but I can't test it right now either . What I would recommend you to do is to print out the $query variable to see what exactly it contains, eg:
echo '$query';
I do that all the time I face a SQL query mixed with code of some sort and need to debug it
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64
Original Poster
Rep:
Hi Mega Man,
Thanks.
I figured it out.
The word 'column' seems to be an 'operator' type
word that doesn't seem to work with the naming
conventions of field names...
So, I changed the field name 'column' to 'location'
and edited the SQL Query accordingly and it now works.
Thank you again for jumping in to help.
Your "echo "$query";" helped.
Thanks,
FirstBorn
----------------------------------
Quote:
Originally Posted by Mega Man X
I can't see anything wrong with the statement, but I can't test it right now either . What I would recommend you to do is to print out the $query variable to see what exactly it contains, eg:
echo '$query';
I do that all the time I face a SQL query mixed with code of some sort and need to debug it
The way I usually figure out such issues is to echo out the query, then feed the echoed output into phpmyadmin and take a look at the useful response that phpmyadmin gives. If phpmyadmin is not available, you can also feed the query into the command line mysql command shell, or you can use something like MySQL Administrator.
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64
Original Poster
Rep:
Quote:
Originally Posted by jiml8
The way I usually figure out such issues is to echo out the query, then feed the echoed output into phpmyadmin and take a look at the useful response that phpmyadmin gives. If phpmyadmin is not available, you can also feed the query into the command line mysql command shell, or you can use something like MySQL Administrator.
Hi jiml8,
Thanks.
Actually, that's how I figured out the issue
with the fieldname...
I tried the Query individually until I noticed
that all of the other fieldnames alone were not
generating errors, but the 'column' fieldname
generated an error (I believe it was a 1064 or
something like that.)
I didn't even think to check there until X
mentioned to echo the query in the script...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.