gr1zzly Posted September 18, 2009 Share Posted September 18, 2009 Hi folks, this one I can't get my head around, as far as I can tell it should work....but it doesn't! (Which probably means it's something really simple - lol) Have this SQL query in the php of my site: $q = "SELECT * FROM blogs WHERE post_page = $page AND post_is_sticky = $is_sticky;"; Where $page is confirmed to store the value news and $is_sticky contains the number 1. The database is ok too - 'blogs' table contains columns 'post_is_sticky' and 'post_page' and rows with the necessary values. This is the odd bit, the query works in phpMyAdmin (with the 'news' and '1' values substituted in). BUT only with quoted values e.g: SELECT *FROM blogs WHERE post_page = 'news' AND post_is_sticky = '1' LIMIT 0 , 30 Why isn't this working in the php version of the code? Please help me Quote Link to comment https://forums.phpfreaks.com/topic/174687-solved-sql-query-error/ Share on other sites More sharing options...
Bricktop Posted September 18, 2009 Share Posted September 18, 2009 Hi gr1zzly, Your first query has a ; after the $is_sticky variable. Change it to read: $q = "SELECT * FROM blogs WHERE post_page = $page AND post_is_sticky = $is_sticky"; Quote Link to comment https://forums.phpfreaks.com/topic/174687-solved-sql-query-error/#findComment-920610 Share on other sites More sharing options...
Alex Posted September 18, 2009 Share Posted September 18, 2009 You still are missing quotes around $page, since it's not a number. $q = "SELECT * FROM blogs WHERE post_page = '$page' AND post_is_sticky = $is_sticky"; Quote Link to comment https://forums.phpfreaks.com/topic/174687-solved-sql-query-error/#findComment-920615 Share on other sites More sharing options...
gr1zzly Posted September 18, 2009 Author Share Posted September 18, 2009 Hi gr1zzly, Your first query has a ; after the $is_sticky variable. Change it to read: $q = "SELECT * FROM blogs WHERE post_page = $page AND post_is_sticky = $is_sticky"; The semi-colon is used in SQL as a de-limiter to signify the end of a statement, much the same as Javascript among others. It makes no difference if you put this in or not since php automatically adds it to the end of the statement when it's submitted anyway. I just add it because I'm the pedantic type lol Thanks to AlexWD, I have tried with quotes, without, just on the $page as well as using {} around them....nothing seems to work!! Quote Link to comment https://forums.phpfreaks.com/topic/174687-solved-sql-query-error/#findComment-920626 Share on other sites More sharing options...
gr1zzly Posted September 21, 2009 Author Share Posted September 21, 2009 Okay turns out that the script file that contains my db connection info associated with $dbc in my code is getting altered when I upload it! The lines of active code are being compressed / moved onto the comment lines above each code block rendering them inert. My 'Spidey' paranioa senses tell me that this may be the work of some monkey whose hacked my site and is playing a 'practical joke' on me. Or is this more likely to just be a bug with the way the file is being sored by the ftp / server. - It works fine with other files though! Hmmm... Quote Link to comment https://forums.phpfreaks.com/topic/174687-solved-sql-query-error/#findComment-922287 Share on other sites More sharing options...
gr1zzly Posted September 21, 2009 Author Share Posted September 21, 2009 Okay turns out that the script file that contains my db connection info associated with $dbc in my code was getting altered when I uploaded it! The lines of active code were being compressed / moved onto the comment lines above each code block rendering them inert. I had tried editing the code back in to the correct line structure and uploading again (several times) with the same result. Then inexplicably it decided to work! I downloaded the file from the server to check and this time the line structure had remained intact. ( ? )... My sever tech support guy suggested that it was something to do with the way line breaks were being handled. Who knows?! Either way it's working okay again now so problem solved! Thanks for all the suggestions guys! Quote Link to comment https://forums.phpfreaks.com/topic/174687-solved-sql-query-error/#findComment-922364 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.