• We just launched and are currently in beta. Join us as we build and grow the community.

Search Record System In PHP

victorrr

Packet Sniffer
V Rep
0
0
0
Rep
0
V Vouches
0
0
0
Vouches
0
Posts
123
Likes
57
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
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. <table class="table table-striped">
  5. <thead>
  6. <tr>
  7. <th class="text-center">No.</th>
  8. <th class="text-center">FirstName</th>
  9. <th class="text-center">LastName</th>
  10. <th class="text-center">Phone Number</th>
  11. <th class="text-center">Email Address</th>
  12. </tr>
  13. </thead>

  14. <tbody>
  15. <?php
  16. error_reporting

    (

    0

    )

    ;
  17. if

    (

    $_REQUEST

    [

    'submit'

    ]

    )

    {
  18. $search_file

    =

    $_POST

    [

    'search_file'

    ]

    ;
  19. $sql

    =

    mysql_query

    (

    "select * from information where firstname like '%$search_file

    %' o

    r lastname like '%$search_file

    %' or ID like '%$search_file

    %' Order by lastname ASC"

    )

    or die

    (

    'Error in query : $sql. '

    .

    mysql_error

    (

    )

    )

    ;

  20. if

    (

    empty

    (

    $search_file

    )

    )

    {
  21. echo

    '<script language="javascript">'

    ;
  22. echo

    'alert("Text field cannot be empty. Please Try it again.")'

    ;
  23. echo

    '</script>'

    ;
  24. header

    (

    "refresh:2; url=index.php"

    )

    ;
  25. }
  26. else

    if

    (

    mysql_num_rows

    (

    $sql

    )

    >

    0

    )
  27. {
  28. $i

    =

    1

    ;
  29. while

    (

    $row

    =

    mysql_fetch_array

    (

    $sql

    )

    )

    {
  30. // Print out the contents of the entry
  31. echo

    '<tr>'

    ;
  32. echo

    '<td class="text-center">'

    .

    $i

    .

    '</td>'

    ;
  33. echo

    '<td class="text-center">'

    .

    $row

    [

    'firstname'

    ]

    .

    '</td>'

    ;
  34. echo

    '<td class="text-center">'

    .

    $row

    [

    'lastname'

    ]

    .

    '</td>'

    ;
  35. echo

    '<td class="text-center">'

    .

    $row

    [

    'phonenumber'

    ]

    .

    '</td>'

    ;
  36. echo

    '<td class="text-center">'

    .

    $row

    [

    'email'

    ]

    .

    '</td>'

    ;
  37. $i

    ++;
  38. }
  39. }
  40. else
  41. {
  42. echo

    '<div class="alert alert-danger" style="width:130px; float:right; margin-top:-142px;">No Results Found!!!</div>'

    ;
  43. }
  44. }
  45. ?>
  46. </tbody>
  47. </table>
  48. </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_1.png


And, this is the result if the user did not found the information in the database.

not_found_0.png


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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,526

323,535

Top