0

Hello,

I made a search option using php every thing is working ine but when i enter 123 in search it does not pull up my any records is it a problem with my code can anyone help me out

 if(isset($_POST['search_now'])){ 
          if(isset($_GET['go'])){ 
              if(preg_match("/^[  a-zA-Z]+/", $_POST['search'])){ 
                  $name=$_POST['search']; 

                  $sql ="SELECT * FROM users WHERE company LIKE '%" . $name ."%'"; 
                  $result = mysqli_query($connection, $sql); 
                  while ($user_row = mysqli_fetch_assoc($result)) {
                    $user_id   = $user_row["u_id"];
                    $f_name    = $user_row["f_name"];
                    $l_name    = $user_row["l_name"];
                    $company   = $user_row["company"];
                    $address   = $user_row["address"];
                    $phone     = $user_row["phone"];
                    $fax       = $user_row["fax"];
                    $mobile    = $user_row["mobile"];
                    $email     = $user_row["email"];
                }
                $name = $f_name . " " . $l_name;
            } else { 
                echo  "<p>Please enter a search query</p>"; 
            } 
          } 
      } 
2
Contributors
5
Replies
20
Views
2 Years
Discussion Span
Last Post by UK-1991
0

Yes but the thing is that 123 is in the database but not retreiving why is that so

0
if(preg_match("/^[ a-zA-Z0-9]+/", $_POST['search'])){ 

or

if(preg_match("/^[ a-zA-Z\d]+/", $_POST['search'])){ 

assuming you'll allow words with numbers.

Edited by pritaeas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.