LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2008, 06:59 AM   #1
FirstBorn
Member
 
Registered: Jul 2008
Location: Hell - aka - Florida
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64

Rep: Reputation: 15
Question 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.

Any Ideas?

Thank you Very Much for Your help in advance.

Thanks,
FirstBorn
 
Old 12-31-2008, 08:20 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
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

P.S: not a PHP programmer myself.

Regards!
 
Old 12-31-2008, 09:59 AM   #3
FirstBorn
Member
 
Registered: Jul 2008
Location: Hell - aka - Florida
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64

Original Poster
Rep: Reputation: 15
Thumbs up

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 View Post
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

P.S: not a PHP programmer myself.

Regards!
 
Old 12-31-2008, 01:49 PM   #4
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Awesome, I'm glad you figured it out FirstBorn Happy new your to you by the way

-X
 
Old 12-31-2008, 05:26 PM   #5
FirstBorn
Member
 
Registered: Jul 2008
Location: Hell - aka - Florida
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by Mega Man X View Post
Awesome, I'm glad you figured it out FirstBorn Happy new your to you by the way

-X
Hey X,

Happy New Year to You, too!

Hope that it's the best ever for You.

Thanks,
FirstBorn
 
Old 12-31-2008, 05:39 PM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
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.
 
Old 12-31-2008, 05:46 PM   #7
FirstBorn
Member
 
Registered: Jul 2008
Location: Hell - aka - Florida
Distribution: Too bad they don't have a distro called Prozaklinux - I use Mandy ... (Mandriva 2008.1)
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jiml8 View Post
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...

It was one of those 'a-ha' moments...

Thanks,
FirstBorn
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP parse/syntax error? ciscotech6509 Programming 2 07-27-2007 02:22 AM
Error Code : 1064 You have an error in your SQL syntax cucolin@ Linux - Server 3 06-11-2007 11:49 AM
MySQL Syntax Error? taylor_venable Programming 2 06-10-2007 08:39 AM
Can't get pass this mysql syntax error Neruocomp Programming 5 07-24-2005 05:25 PM
php trying to connect to local sql, error no such database feetyouwell Programming 11 02-08-2005 12:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration