I have a search form on a seperate page. I am trying to get the information that is searched in that form to display in a table while also displaying the rest of the data from that search that is in a sql database. A little bit of background: this is for a library to make searxhing obituaries quicker. Right now i have gotten rid of all error messages and the title and hearders of the table are displayed, but there is no information being displayed. Full disclosure: this is not all original code, some of this code i have found on other sites and modified it to fit what I need. That being said it's possible i could have missed a few changes.
<?php
$servername = "localhost";
$username = "root";
$password = "*****";
$dbname = "hfa";
$link = mysqli_connect("localhost", "root", "*****", "hfa");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$_GET = array('first_name', 'last_name', 'age', 'year_of_birth',
'year_of_death', 'date_of_death', 'month_of_death', 'funeral_home', 'city',
'county');
// gets value sent over search form
$first_name = mysqli_real_escape_string($link, $_REQUEST['first_name']);
$last_name = mysqli_real_escape_string($link, $_REQUEST['last_name']);
$age = mysqli_real_escape_string($link, $_REQUEST['age']);
$year_of_birth = mysqli_real_escape_string($link,
$_REQUEST['year_of_birth']);
$year_of_death = mysqli_real_escape_string($link,
$_REQUEST['year_of_death']);
$date_of_death = mysqli_real_escape_string($link,
$_REQUEST['date_of_death']);
$month_of_death = mysqli_real_escape_string($link,
$_REQUEST['month_of_death']);
$funeral_home = mysqli_real_escape_string($link, $_REQUEST['funeral_home']);
$city = mysqli_real_escape_string($link, $_REQUEST['city']);
$county = mysqli_real_escape_string($link, $_REQUEST['county']);
$sql = mysqli_query($link, "SELECT *
FROM obituaries
WHERE FirstName AND LastName AND Age AND YearOfBirth AND YearOfDeath AND
DateOfDeath AND MonthOfDeath AND FuneralHome AND City AND County
LIKE ('$first_name' AND '$last_name' AND '$age' AND '$year_of_birth' AND
'$year_of_death' AND '$date_of_death' AND '$month_of_death' AND
'$funeral_home' AND '$city' AND '$county')");
$q_res = mysqli_fetch_array($sql);
$results = mysqli_fetch_row($sql);
if(mysqli_query($link, "SELECT *
FROM obituaries
WHERE FirstName AND LastName AND Age AND YearOfBirth AND YearOfDeath AND
DateOfDeath AND MonthOfDeath AND FuneralHome AND City AND County
LIKE ('$first_name' AND '$last_name' AND '$age' AND '$year_of_birth' AND
'$year_of_death' AND '$date_of_death' AND '$month_of_death' AND
'$funeral_home' AND '$city' AND '$county')")){
echo "Success ";
} else{
echo "ERROR: Not able to execute $sql. " . mysqli_error($link);
}
?>
<html>
<head>
<h1>Results</h1>
</head>
<body>
<table style="width:100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Year Of Birth</th>
<th>Year Of Death</th>
<th>Date Of Death</th>
<th>Month Of Death</th>
<th>City</th>
<th>County</th>
<th>Funeral Home</th>
</tr>
</thead>
<tbody>
<tr style="width:100%">
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['FirstName']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['LastName']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['Age']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['YearOfBirth']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['YearOfDeath']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['DateOfDeath']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['MonthOfDeath']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['City']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['County']."</h3></p>";
}
} ?> </th>
<th> <?php if(mysqli_num_rows($sql) > 0){
while($results = mysqli_fetch_array($sql)){
echo "<p><h3>".$results['FuneralHome']."</h3></p>";
}
} ?> </th>
</tr>
</tbody>
</table>
</html>
<?php
$link->close();
?>
I don't know why it's not printing the data, could someone please help?