<?php
$search_input = $_POST["search_input"];
include_once("connection_to_db.php");
if(!isset($search_input))
{
print("Nothing to search !");
return;
}
//Queries products where the search input is similiar to the title, artist or format of a product
$query_search = "SELECT * FROM waxItem WHERE title OR artist LIKE '%".$search_input."%'";
$query_search_result = mysql_query($query_search)
or die(mysql_error());
$num_rows_search = mysql_num_rows($query_search_result);
?>
The code above does not work when i add “OR artist”.
The code does work and search results are displayed when only one field is compared to the database records.
What am i doing wrong?
You cannot state the same LIKE criteria for multiple fields. You have to specify it per field. Even though you can do this but this is definitely not a recommended approach due to SQL Injection Attacks. Please read this SQL Injection
You have to change
to