Jump to content

[SOLVED] MySQL Syntax Error On Previously Fine Query


peridian

Recommended Posts

Hello,

The following query:

[code]SELECT BODY FROM Site WHERE TITLE LIKE 'ADVERTS%%' && SITE = 2[/code]

was in use via a mysql_query command on my website for ages.  I recently decided to re-write all the code for the site, and now mysql_error is telling me that I have a syntax problem near the end of the query.

I don't know if the version of MySQL has been updated on my server (the documentation indicates 5.0), but what's frustrating is not only did this used to work, typing this query into the SQL builder in phpmyadmin on the server still works fine and returns the correct results.

I can only assume either my php code is wrong and is resulting in what appears to be an error with MySQL, or that there is something wrong with the syntax which phpmyadmin fixes before passing the query.

Can anybody spot anything wrong with the above?

If not, are there any obvious pitfalls I might want to check for in my php code when using a class to represent the database connection?  I'm pretty sure I've already checked for any and all issues surrounding use of quotes.

Regards,
peridian.
Link to comment
Share on other sites

In the words of a wiseman...

"DOH!"

I've spent hours trying to figure this out, and within minutes of posting I've figured out the answer.

For anybody who might also do this:

In the inner workings of the class, all code gets passed through a 'cleansing' function to try and reduce the risk of damaging input in the SQL query.

What I didn't realise was that the query I was using also got passed through HTMLSpecialChars.  This of course changed all the strange non-character symbols into their HTML equivalents, which MySQL would not accept.

I didn't realise this of course because the error message was being displayed from a die command on a web page, so of course the query when displayed there appears fine.

DOH!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.