Welcome to WebmasterWorld Guest from 50.17.117.221

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

A Disappearing Syntax Error Message

Hit F5 and the message disappeared

     
8:21 pm on May 20, 2012 (gmt 0)

Preferred Member from GB 

10+ Year Member Top Contributors Of The Month

joined:July 25, 2005
posts: 387
votes: 7


Hi,

I suspect gremlins. I've got a simplest MySQL query

$toProcess = mysql_query("SELECT * FROM url_list ORDER BY id DESC LIMIT 7 WHERE type='get'");


The first time I ran the test script I got a blank screen.
Then I hit F5 and got a Syntax error message suggesting that I have to consult the manual and check for errors around WHERE type='get'
I hit F5 again and I got a blank screen again.

Unless both the MySQL manual and W3schools tutorial are wrong, there is no syntax error in my query.

Please help!
8:29 pm on May 20, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


Change it to this

$toProcess = mysql_query("SELECT * FROM url_list ORDER BY id DESC LIMIT 7 WHERE type='get'") or die(mysql_error());

and you'll get a more definitive error message, if you can manage to reproduce it.
9:03 pm on May 20, 2012 (gmt 0)

Preferred Member from GB 

10+ Year Member Top Contributors Of The Month

joined:July 25, 2005
posts: 387
votes: 7


Aha, good idea, thank you.

This is the error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE type='get'' at line 1

The funny thing is that it's not the line 1. It should be line 3.
9:40 pm on May 20, 2012 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4842
votes: 1


I should have read the query more closely rather than the scenario. Your syntax is a little off

SELECT * FROM url_list WHERE type='get' ORDER BY id DESC LIMIT 7

The WHERE part of the query is in the wrong place, the above is the correct place. If you think of the SQL as left to right logic it makes sense that the WHERE statement should be there, as ordering and limiting would be done after the filtering done in the WHERE command.
8:38 pm on May 25, 2012 (gmt 0)

Preferred Member from GB 

10+ Year Member Top Contributors Of The Month

joined:July 25, 2005
posts: 387
votes: 7


Yes indeed, it makes sense. For some reason I thought that it doesn't matter. Now working perfectly, thank you!