Mysql search!????

A

Anonymous

Guest
Code:
// The form: 
<form method="POST" action=""> 
Search Word: <input type="text" name="query"> 
<input type="SUBMIT" value="Search!"> 
</form> 

<? 
// PHP Search Script 

$sql = mysql_query("SELECT topico,texto FROM yourtable WHERE topico LIKE %$query% OR texto LIKE %$query%") or die (mysql_error()); 

while(list($column1, $column2)=mysql_fetch_array($sql)){ 

echo "Result: $column1, $column2 <br />"; 

} 
?>

i search for hello, and gives-me 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 '%hello% OR texto LIKE %hello%' at line 1
 
Im fairly sure it needs to be:
topico LIKE '%$query%' OR texto LIKE '%$query%'"

not

topico LIKE %$query% OR texto LIKE %$query%"

--Added the quotes around %query%

Hope it isnt too late, seems like this forum died!
 
Back
Top