I'm trying to create a search box for my project. It's job is to take the input, look for the name, and if found, echo it. It doesn't work though. I've gone through tons of tutorials, and they all mostly do the same as me. I checked my error log and it seems the query is at fault.Help is appreciated.
<div class="subjectBox" style="margin-bottom: 5px;">Patients:</div>
<?php
include 'database.php';
$search = $_POST['search'];
if(isset($_POST['submit'])){
if($search === ''){
$message = "<div style='margin-bottom: 55px;' class='titleBox'>Please fill in all values.</div>";
} elseif (!empty($search)) {
$search = strtoupper($search);
$search = strip_tags($search);
$search = trim($search);
$data = mysql_query("SELECT * FROM patient WHERE fname LIKE '%$search%'");
while ($row = mysql_fetch_array($data)) {
$message = "<div class='titleBox'>" . $row['fname'] . "</div>";
}
$matches = mysql_num_rows($data);
if($matches === 0) {
$message = "<div class='titleBox'>Sorry, but we can not find an entry to match your query.</div>";
}
$message1 = "<div class='titleBox'><b>Searched For:" . $search . "<b/></div>";
}
}
?>
<form action="patient.php" method="post">
<input type="text" class="subjectBox" autocomplete="off" name="search" placeholder="Enter a name to search..." style="margin: auto; display: block; margin-bottom: 5px; width: 595px;">
<input type="submit" value="go." name="submit" class="titleBox" style="width: 595px; ">
</form>
<?php if(!empty($message1)): ?><p><?= $message1 ?></p><?php endif; ?>
<?php if(!empty($message)): ?><p><?= $message ?></p><?php endif; ?>