Solved

PHP SEARCH PROBLEM, Please Help

Posted on 2011-03-24
6
259 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
Technology Partners: 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 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
form validation - make sure at least 1 checkbox is selected 18 67
How efficient to move databases to Azure? 5 60
Make login page safer 3 35
php subtract from date 2 31
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

730 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