query, search, PHP, MySQL - problems

Hi

I am having trouble getting my HTML/PHP pages to talk to my MySQL database

I have two lines of code that are

[php]$search=$_POST[‘search’];

$query = mysql_query(‘SELECT * FROM historyflix WHERE name LIKE "’.$search.’"’) or die("Couldn’t execute query. ". mysql_error()); [/php]

these work fine as long as they keyword is exact (though is not case-sensitive) but I want to return results that also include the keyword.

I have read up that I need to include % before and after $search to act as wild cards, but wherever I place them I get error messages - also this line of codes seems to have a lot of single quotes, double quotes and full stops, but unless I have them all the line of code does not work (ps - the original line of this code had = instead of LIKE, I don’t really know what the difference is)

You need to add wild cards either side of your search string:

[php]
$search=$_POST[‘search’];

$query = mysql_query(‘SELECT * FROM historyflix WHERE name LIKE %"’.$search.’"%’) or die("Couldn’t execute query. ". mysql_error());
[/php]

So, if you search word is “and” it will find “and”, “sand”, “ampersand” “apples and pears” etc.

[php]
$query = mysql_query(‘SELECT * FROM historyflix WHERE name LIKE "%’.$search.’%"’)[/php]

Yes, that’s the one. ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service