Solved

Search, PHP & mySQL Help

Posted on 2011-03-24
2
361 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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 …

762 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

16 Experts available now in Live!

Get 1:1 Help Now