Im trying to get an SQL query to work but im having problems. I create a form to submit the search:
<form action="" method="post">
<input type="submit"></input>
<select name="category">
<option value="all">All</option>
<option value="id">ID</option>
<option value="firstname">First Name</option>
<option value="lastname">Last Name</option>
<option value="dob">DOB</option>
</select>
<input name="searchTerm" type="test"></input>
</form>
and the php:
$category = $ POST['category'];
$searchTerm = $ POST['searchTerm'];
$con=mysqli_connect("localhost","root","","158_252");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($category = "all"){
$result = mysqli_query($con,"SELECT * FROM catalogue");
}
else{
$result = mysqli_query($con,"SELECT * FROM catalogue WHERE $category = $searchTerm");
}
there is a bit more php code but the problem occurs somewhere in here
i want to check if $category is value 'all' at which display everything in the SQL Database. no matter what the form values are set to, it always outputs the whole database,
i think its my syntax with PHP as im new to it so any help is appreciated.