I am attempting to make a search bar on my website that will query mysql database and return the results in a fashionable way. The search will be used to look for names. For instance, the user can type in "John Doe" and any information on John Doe will be returned. Unfortunately, whenever I click the submit button and my site transitions to 'search.php' the page is completely blank. I have tested my connection to the database and know that it is working. Is there something wrong with my code such that absolutely nothing shows up? It does not even revert the user back to the index.html.
I have a search bar on my index.html as follows:
<form id="navsearch" class="form-group" role="search" action="search.php" method="post">
<div class="input-group" display="inline">
<input name="search" type="text" value="Search" class="form-control" placeholder="Search">
<span class="input-group-btn">
<button class="btn btn-default btn" name="submit" class="btn btn-lg" type="submit">
<span class="glyphicon glyphicon-search" name="submit"></span>
</button>
</div>
</form>
Here is the php on 'search.php':
<?php
//make connection to database
$connection = mysqli_connect('xxx.xxxx', 'root', 'hello', 'awstutorial', 3306);
$search_word = '';
if (isset($_POST['submit'])) {
if (!empty($_POST['search'])) {
$search_word = $_POST['search'];
$search = mysqli_real_escape_string($connection, $_POST['search']);
$query = "SELECT * FROM data WHERE name LIKE '%$search%' ";
$search_query = mysqli_query($connection, $query);
// START RESULTS
if ($result = mysqli_query($connection, $query)) {
$to_display = "<div>";
while ($row = mysqli_fetch_array($result)) {
if ((substr($row['file'], -3) == 'jpg') || (substr($row['file'], -3) == 'JPG') || (substr($row['file'], -3) == 'PNG') || (substr($row['file'], -3) == 'png') || (substr($row['file'], -3) == 'GIF') || (substr($row['file'], -3) == 'gif'))
$img_url = "uploads/" . $row['file'];
else {
if ((strtolower(substr($row['file'], -3) == 'png')) || (strtolower(substr($row['file'], -3) == 'doc')) || (strtolower(substr($row['file'], -3) == 'docx') ))
$img_url = "uploads/pdf_logo.png";
else
$img_url = "uploads/no_doc.png";
}
$to_display .= "<a href='story.php?id=".$row['id']."' class='col-md-3 asdivs portfolio-box fancybox fancybox.iframe'><img alt='' class='img-responsive' src='" . $img_url . "'><div class='portfolio-box-caption'>
<div class='portfolio-box-caption-content'>
<div class='project-category text-faded'>
Read
</div>
<div class='project-name'>"
. $row['name'] . "'s Story
</div>
</div>
</div>" . $row['name'] . " - " . $row['email'] . "</a>";
}
}
$to_display .= "</div><div style='clear:both;'></div>";
} else {
header("Location: index.html");
}
}
?>