Hey, I need to create a search engine that searchs through a database but the wild card doesn't work for me:
<?php
include ('header.php');
$s = $_POST['search_term'];
$by = $_POST['by'];
if(!$s && $by) // Check that the details are entered correctly
{
echo '<p>You have not entered the required fields</p>';
exit();
}
// LIKE '%$searchterm%'
$query = "SELECT * FROM products WHERE artist LIKE '% $s %'";
$result = mysql_query($query) or trigger_error("Query: $query \n<br />Mysql error: " . mysql_error());
if(mysql_affected_rows() >= 1)
{
while($row = mysql_fetch_array($result))
{
echo '<p>Your search result for ' .$search_term. '';
echo '<blockquote>';
echo '<img src="' .$row['pic']. '">';
echo '<p>' .$row['desc']. '<br />';
echo 'Price: ' .$row['price']. '<br />';
echo '</blockquote>';
}
}else{
echo '<p>No artist found, did you spell it right?</p>';
}
?>
Any help would be great. Thanks.