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>"; 
            } 
          } 
      } 

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

How will I make it to search both words and numeric

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.

Thank You it worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.