Jump to content

[SOLVED] A simple search query is broken.


daedalous

Recommended Posts

SQL Server version: 5.0.51a

Raw SQL, php var omitted:

SELECT * FROM quote WHERE quote LIKE '%apple%'

This code executes fine. 'quote' is the name of the table, in addition to being the name of a col in 'quote'.

This really should be quite simple, and the above code executes without problem in phpmyAdmin, however, when used with this code:

$result = mysql_query("SELECT * FROM quote WHERE quote LIKE '%$find%'");
	if (@mysql_query($result)){
	while($row = @mysql_fetch_array($result)){
		echo $row['quote'];
			}

It doesn't get past the if statement and gives me this:

 

mySQL error: 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 'Resource id #3' at line 1

 

I've echo'd the SQL query as a variable, with the php variable $find, and it prints correctly. It's a valid query. But I still get the syntax error above. Any ideas?

 

Thanks in advance,

Daed

 

ps. I'm very new to php and mysql, my apologies if it's a simple mistake.

Link to comment
https://forums.phpfreaks.com/topic/127820-solved-a-simple-search-query-is-broken/
Share on other sites

You are running a query, then running the queries result inside another query, which is why you are getting an error. $result contains a MySQL Resource ID, as you've seen. You need to remove the if() statement, or change it to if($result){.

Archived

This topic is now archived and is closed to further replies.

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