Question

I have this query:

$get_active_image = mysql_query("SELECT * FROM media WHERE media_type = 'image' 
AND range = 'global' ORDER BY news_id DESC LIMIT 0,1");

and it works just perfectly fine in my localhost.

But, when I tried uploading it in freehosting sites, it gives me this error message:

supplied argument is not valid

It seems that in my query, WHERE and AND cannot come together, because the query works if I remove the AND - plus - I am 100% sure range GLOBAL exists, as said, it works in my localhost.

I just wanna know why it's not working when I host it.

Also, database connection is 100% working. Nothing else is wrong. Just the query with the AND doesn't work.

If I miss something, please enlighten me. Thank you.

Was it helpful?

Solution

Range is a reserved word.

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Try adding backticks around it.

$get_active_image = mysql_query("SELECT * FROM media WHERE media_type = 'image' 
AND `range` = 'global' ORDER BY news_id DESC LIMIT 0,1");

It may work on your local host due to a different version of MySQL in which it is NOT a reserved word.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top