Solved

PHP SEARCH PROBLEM, Please Help

Posted on 2011-03-24
6
254 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
  • 3
  • 2
6 Comments
 
LVL 4

Assisted Solution

by:qasim_md
qasim_md earned 100 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 400 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The viewer will learn how to count occurrences of each item in an array.
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 …

747 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

11 Experts available now in Live!

Get 1:1 Help Now