If you are looking for a source code for
Search Record System In PHP then you are at the right place. This is a simple program using
PHP and
MySQL for searching record in the database.
This program contains a TextBox where the user entering the keyword and button to generate searching and table to show the information. And, the user can search in the TextBox by FirstName, LastName, or ID Number.
Form Input Field - HTML
This HTML Form input field where the user types the keyword for search.
<form method="post" action="" name="form1" id="form1">
<p style="font-size:18px; margin-left:100px;">
Type the First Name, Last Name, or ID Number of the User
<p style="font-size:18px; margin-left:100px;">Search User
<input type="text" autofocus="autofocus" name="search_file" id="search_file" style="width:230px; font-size:18px;" class="textboxclass" />
<input type="submit" style="font-size:18px; margin-top:-9px;" class="btn btn-primary" name="submit" value="Filter"></p>
Showing Results
This source code where the information display.
<div class="container">
<div class="alert alert-success"><center> <h4>Record Results </h4></center> </div>
<br />
<table class="table table-striped">
<thead>
<tr>
<th class="text-center">No.</th>
<th class="text-center">FirstName</th>
<th class="text-center">LastName</th>
<th class="text-center">Phone Number</th>
<th class="text-center">Email Address</th>
</tr>
</thead>
<tbody>
<?php
if ($_REQUEST['submit']) {
$search_file = $_POST['search_file'];
$sql = mysql_query("select * from information where firstname like '%$search_file%' or lastname like '%$search_file%' or ID like '%$search_file%' Order by lastname ASC") or
die('Error in query : $sql. ' .mysql_error());
if (empty($search_file)) {
echo '<script language="javascript">';
echo 'alert("Text field cannot be empty. Please Try it again.")';
echo '</script>';
header( "refresh:2; url=index.php" );
}
{
$i = 1;
// Print out the contents of the entry
echo '<tr>';
echo '<td class="text-center">' . $i . '</td>';
echo '<td class="text-center">' . $row['firstname'] . '</td>';
echo '<td class="text-center">' . $row['lastname'] . '</td>';
echo '<td class="text-center">' . $row['phonenumber'] . '</td>';
echo '<td class="text-center">' . $row['email'] . '</td>';
$i++;
}
}
else
{
echo '<div class="alert alert-danger" style="width:130px; float:right; margin-top:-142px;">No Results Found!!!</div>';
}
}
?>
</tbody>
</table>
</div>
And, this is the database script.
Output:
This is the result if the user found the information in the database.
And, this is the result if the user did not found the information in the database.
So what can you say about this work? Share your thoughts in the comment section below or email me at
[email protected]. Practice Coding. Thank you very much.