Search Record System In PHP

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.
  1. <form method="post" action="" name="form1" id="form1">
  2. <p style="font-size:18px; margin-left:100px;">
  3. Type the First Name, Last Name, or ID Number of the User
  4. </p>
  5. <br />
  6. <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" />
  7. <input type="submit" style="font-size:18px; margin-top:-9px;" class="btn btn-primary" name="submit" value="Filter"></p>
  8. </form>
Showing Results This source code where the information display.
  1. <div class="container">
  2. <div class="alert alert-success"><center> <h4>Record Results </h4></center> </div>
  3. <br />
  4.  
  5. <table class="table table-striped">
  6. <thead>
  7. <tr>
  8. <th class="text-center">No.</th>
  9. <th class="text-center">FirstName</th>
  10. <th class="text-center">LastName</th>
  11. <th class="text-center">Phone Number</th>
  12. <th class="text-center">Email Address</th>
  13. </tr>
  14. </thead>
  15.  
  16. <tbody>
  17. <?php
  18. if ($_REQUEST['submit']) {
  19. $search_file = $_POST['search_file'];
  20. $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());
  21.  
  22. if (empty($search_file)) {
  23. echo '<script language="javascript">';
  24. echo 'alert("Text field cannot be empty. Please Try it again.")';
  25. echo '</script>';
  26. header( "refresh:2; url=index.php" );
  27. }
  28. else if (mysql_num_rows($sql) > 0)
  29. {
  30. $i = 1;
  31. while ($row = mysql_fetch_array($sql)) {
  32. // Print out the contents of the entry
  33. echo '<tr>';
  34. echo '<td class="text-center">' . $i . '</td>';
  35. echo '<td class="text-center">' . $row['firstname'] . '</td>';
  36. echo '<td class="text-center">' . $row['lastname'] . '</td>';
  37. echo '<td class="text-center">' . $row['phonenumber'] . '</td>';
  38. echo '<td class="text-center">' . $row['email'] . '</td>';
  39. $i++;
  40. }
  41. }
  42. else
  43. {
  44. echo '<div class="alert alert-danger" style="width:130px; float:right; margin-top:-142px;">No Results Found!!!</div>';
  45. }
  46. }
  47. ?>
  48. </tbody>
  49. </table>
  50. </div>
And, this is the database script.
  1. <?php
  2. mysql_select_db('users',mysql_connect('localhost','root',''))or die(mysql_error());
  3. ?>

Output:

This is the result if the user found the information in the database. Found And, this is the result if the user did not found the information in the database. Not Found 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.

Comments

Submitted bysalim21on Fri, 11/16/2018 - 23:54

Hi, i like your project but there is an error, Please can you fix the following error when i runt the php. Thank you Fatal error: Uncaught Error: Call to undefined function mysql_select_db() in C:\xampp\htdocs\3\dbcon.php:2 Stack trace: #0 C:\xampp\htdocs\3\header.php(10): include() #1 C:\xampp\htdocs\3\index.php(21): include('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\3\dbcon.php on line 2

Add new comment