Solved

Search, PHP & mySQL Help

Posted on 2011-03-24
2
364 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:NeoAshura
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35207922
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
 
LVL 6

Author Closing Comment

by:NeoAshura
ID: 35208663
cheers buddy
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now