Solved

Search, PHP & mySQL Help

Posted on 2011-03-24
2
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

632 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