[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP SEARCH PROBLEM, Please Help

Posted on 2011-03-24
6
Medium Priority
?
267 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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