Search, PHP & mySQL Help

Hi Experts, Ive got a search function. Which is ment to be able to search for either name or number when entenerd into the search field and hit enter. It returns the name correctly but does not return the number it says there is no query enterd.

can someone assist me with this??

code is attached.

many thanks.


<?php
session_start();
ob_start();
?>
<?
error_reporting(E_ALL);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

    
<title>Talk Business Solutions</title>

        <link id="css_default" href="unity_scm.css" 
rel="stylesheet" type="text/css">
    </head><body>
        <div class="fullpage">

            <div class="header">
              <div align="center"><span class="secondbar"><img src="header2.jpg" width="967" height="124" alt="headerimage" /></span></div>
            </div>
            <div class="leftcol">

	      <div class="bar">&nbsp;</div>
        <div class="bar">&nbsp;</div>

                <div align="center"><a name="sitenav"></a>
                  <ul class="navbar">
                  <li><a 
href="logout.php" accesskey="1">Logout</a></li>
                    <li><a href="company.php" accesskey="2">Select Company</a></li>
                    <li><a href="https://retail.o2.co.uk/O2Gateway/CSE/" accesskey="3">O2 Business Gateway</a></li>
                    <li><a href="https://retail.o2.co.uk/O2Gateway/rfe/demand/home.do" accesskey="4">O2 Retail Gateway</a></li>
                    
                    <li><a href="http://sales.o2.co.uk/login.asp" accesskey="5">O2 Sales Website</a></li>
                    <li><a href="https://o2businessaccount.o2.co.uk/" accesskey="6">O2 Bill Analyser</a></li>
                    <li><a href="https://citymaintrak.com/" accesskey="7">City Main Insurace</a></li>
                     <li><a href="http://uk.fedex.com" accesskey="8">FedEx</a></li>
                      <li><a href="http://www.gsmarena.com/" accesskey="7">GSM Arena</a></li>
                    
                    
                    
                    
                  </ul>
                  </ul>
                </div>
                <div class="sidebarbottom">&nbsp;</div>
            </div>
            <div class="mainarea">
            
    <div align="center">


<html>
<head>
  </div>
          <div class="pagearea">
                    <div align="center"><a name="content"></a>
                      
                    </div>
            <h2 align="center">Talk Business Solutions</h2>

<p align="center" style="font-size: 0.8em; border-color: rgb(221, 221, 221);"><em>Here is a list of all customers in relation to the company selected..</em></p>

<h3 align="center" class="banner">Client Search</h3>
<p align="center"></p>


<title></title>
<div align="center">
  <body>
<?php 
error_reporting(E_ALL);
 if(isset($_POST['submit'])){ 
	  if(isset($_GET['go'])){ 
	  if(preg_match("/^[  a-zA-Z]+/", $_POST['searchterm'])){ 
	  $searchterm=$_POST['searchterm']; 
	  //connect  to the database 
	include 'myphp.php';
	  //-query  the database table 
	  
	  
	  $sql="SELECT mobile_number, customer_name FROM customer_details WHERE customer_name LIKE '%" . $searchterm .  "%' AND (customer_name LIKE '%" . $searchterm .  "%' OR mobile_number LIKE '%" . $searchterm .  "%')"; 
	  //-run  the query against the mysql query function 
	  $result=mysql_query($sql) or die(mysql_error());
	   var_dump ($sql);
	  //-create  while loop and loop through result set 
	  while($row=mysql_fetch_array($result)){ 
	          $customer_name  =$row['customer_name']; 
	          $mobile_number =$row['mobile_number']; 
	           var_dump ($result);
	 
	  //-display the result of the array 
	  echo "<ul>\n"; 
	  echo "<li>" . "<a  href=\"mobilenum.php?val=$customer_name\">"   .$customer_name . " " . $mobile_number .  "</a></li>\n"; 
	  echo "</ul>"; 
	  } 
	  } 
	  else{ 
	  echo  "<p>Please enter a search query</p>"; 
	  } 
	  } 
	  } 
	?> 
    </div>
<tr>
</div>
<td width="100" valign="top"></td>
<td width="100" nowrap><div align="center"><br />
  
  
</div></td>
<p align="center"></p>

<th></th> 
  <td></td>
  <div align="center"><br/>
    <img src="" width="" height="
                              ">
    
    
  </div>
<div align="center">
  </div>
  </div>
  
</div>
<div class="spacer"></div>

         
            <div class="footer">
            	<div class="secondbar_bottom">
            	  <div align="center">
            	    <?php //echo 'Welcome ' .''. $_SESSION['myusername'];?>
          	    </div>
            	</div>
            	<div class="bottombar">
            	  <div align="center">Talk Business Solutions</div>
            	</div>
            </div>
        <div align="center">
              </div>
    </div>
</body></html>

Open in new window

LVL 6
NeoAshuraAsked:
Who is Participating?
 
Rik-LeggerConnect With a Mentor Commented:
It is because of this limitation:

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

Open in new window


which only accepts spaces and a through z.

Replace it with this:

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

Open in new window

0
 
NeoAshuraAuthor Commented:
cheers buddy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.