Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Search people</title>
- </head>
- <body>
- <?php require 'db/connect.php'; ?>
- <h3>Search people</h3>
- <?php
- $records = array();
- $errors = array();
- // If button Search is pressed
- if (isset($_POST['search'])){
- // Grab data from the field search_fn
- $search_fn = trim($_POST['search_fn']);
- // If field search_fn is empty
- if (empty($search_fn)){
- $errors[] = '<font color="red"><strong>Error:</strong> Field search is important</font><br /><br />';
- } else {
- // Field search_fn should cointaint at least 3 chars
- if (strlen($search_fn) < 3){
- $errors[] = '<font color="red"><strong>Error:</strong> Field search should cointaint at least 3 chars!</font><br /><br />';
- } else {
- // Search database
- if ($results = $db->query("SELECT * FROM `people` WHERE `first_name` LIKE '%{$search_fn}%'")){
- if ($results->num_rows){
- while ($row = $results->fetch_object()){
- $records[] = $row;
- }
- $results->free();
- } else {
- $errors[] = '<font color="red"><strong>Error:</strong> User doesn\'t exist!</font><br /><br />';
- }
- }
- }
- }
- }
- ?>
- <form method="post" action="">
- Search by First name: <input type="text" name="search_fn">
- <input type="submit" name="search" value="Search">
- </form><!-- end form -->
- <?php
- echo '<hr />';
- foreach ($records as $r){
- echo $r->first_name,' ',$r->last_name,' ',$r->created, '<br />';
- }
- echo implode($errors);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement