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
Solved

Search, PHP & mySQL Help

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 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