Jump to content

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

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.