I really need some help with this one. I'm trying to create a search bar for my site that will display the proteins that are available. I'v not got much knowledge on how to do this and im using some script that I have been given form my tutor.
This is the script so far
<?php
$search = $_GET["search"];
require "db.inc";
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);
$query = "SELECT protien.ProtienID,
protien.Protien Image,
protien.Protien Name,
protien.Protien Flavour,
protien.Protien Price,
protien.Protien Description
FROM protien";
if ($search != "All")
// $query .= " AND r.region_name = 'Coonawarra' ";
$query .= " AND Protien Name = '$regionName' ";
$query .= " ORDER BY Protien Name";
$result = mysql_query($query,$connection) OR die(mysql_error($query));
?>
And the form is
div class="SideBar">
<div id="tfheader">
<form method="get" action="ProteinSearch.php" id="searchform">
<input type="text" name="search" />
<input type="submit" name="submit" value="Search" />
</form>
Try to change this like
if ($search != "All")
$query .= " WHERE `Protien Name` = '$regionName' ";
You have to use WHERE
instead of AND
and also your column name contains space so you need to enclose it with backquotes
.