peridian Posted December 13, 2006 Share Posted December 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/30502-solved-mysql-syntax-error-on-previously-fine-query/ Share on other sites More sharing options...
peridian Posted December 13, 2006 Author Share Posted December 13, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/30502-solved-mysql-syntax-error-on-previously-fine-query/#findComment-140421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.