?
Solved

PHP SEARCH PROBLEM, Please Help

Posted on 2011-03-24
6
Medium Priority
?
263 Views
Last Modified: 2012-05-11
Hi Experts,

I have this search function, It should allow the user to search by customer_name and contact_mobile.

It goes to my script but does not return any results. the while loop fails expecting a boolean value.

any Ideas??

code is attached. Modifications are welcomed..
<?php 
 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 contact_mobile, customer_name FROM customer WHERE customer_name LIKE '%" . $searchterm .  "%' OR mobile_number LIKE '%" . $searchterm ."%'"; 
	  //-run  the query against the mysql query function 
	  $result=mysql_query($sql); 
	   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['contact_mobile']; 
	           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>"; 
	  } 
	  } 
	  } 
	?>

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
  • 3
  • 2
6 Comments
 
LVL 4

Assisted Solution

by:qasim_md
qasim_md earned 400 total points
ID: 35205872
Convert your mobile_number column to varchar::: code below :::

$sql="SELECT contact_mobile, customer_name FROM customer WHERE customer_name LIKE '%" . $searchterm .  "%' OR convert(varchar(20),mobile_number) LIKE '%" . $searchterm ."%'";

did that help ??? let me know ...
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35206327
it already is varchar11 set in the database.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35206931
add this to the top:
error_reporting(E_ALL);
you may see why the query fails.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 1600 total points
ID: 35206937
And do it like this:

$result=mysql_query($sql) or die(mysql_error());
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35207087
i did that but removed it when i posted code the error i get is..

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in I:\EasyPHP-5.3.5.0\www\search.php on line 15

0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35207114
$result=mysql_query($sql) or die(mysql_error()))

solved it, I wasnt calling correct table name. thanks .
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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 …
Suggested Courses

770 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