Jump to content

Search DB with Multiple Search Strings


lilman

Recommended Posts

I want to search my db's columns title and author. Here is the code I've written:

[code]$query = "SELECT * FROM bookcatalog WHERE title like \"%$title%\", author like \"%$author%\"";
$runquery=mysql_query($query) or die(mysql_error());[/code]

When I run it I get this 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 ' author like "%Isaac%"' at line 1

It worked fine until I added this part of the code [code], author like \"%$author%\"[/code]

Any help would be great!
Link to comment
https://forums.phpfreaks.com/topic/30062-search-db-with-multiple-search-strings/
Share on other sites

Replace the comma with either 'AND' or 'OR' (without the quotemarks) depending on what you want.

"SELECT * FROM bookcatalog WHERE title like \"%$title%\" AND author like \"%$author%\""

"SELECT * FROM bookcatalog WHERE title like \"%$title%\" OR author like \"%$author%\""

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.