Jump to content

[SOLVED] SQL query error


gr1zzly

Recommended Posts

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

Link to comment
Share on other sites

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!!  :shrug:

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!  :D

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.