I am trying to search a mysql database in php: my motive is to search by 4 dropdown menu parameters namely: Option 1 Option 2 Option 3 Option 4. All in dynamically populated from a database.
Please see below the search form in image.
The problem is that I can't get it right. I'm not sure what's happening but the result returns
Please enter a search query.
Please take a look below:
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['bloodgroup'])){
$name=$_POST['bloodgroup'];
//connect to the database
$db=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("databasename");
//-query the database table
$sql="SELECT fullname, bloodgroup, Phone FROM donors WHERE bloodgroup LIKE '%" . $bloodgroup . "%' AND city LIKE '%" . $city ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$fullname =$row['$bloodgroup'];
$bloodgroup=$row['state'];
$city=$row['city'];
$city=$row['donortype'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"search.php?id=$ID\">" .$fullname . " " . $bloodgroup . " " . $Phone . "</a></li>\n";
echo "</ul>";
}
} else {
echo "<p>Please enter a search query</p>";
}
}
}
?>
Pls help.
` each time. You have a lot here to clean up before we can answer the question.
– Jay Blanchard Sep 30 '14 at 13:00