Jump to content



  • Please log in to reply
2 replies to this topic

#1 a2bardeals

  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationAnn Arbor, MI

Posted 12 September 2006 - 01:15 AM

i am having some trouble searching my database. the db is set up like an address book. name, address, city, state, phone, id(int) *auto_increment*  i created the db then created a php script to populate the db with entries. now i want to search those entries. i tried going this route but it returns a blank page.

of course i have a form page (search.html) that the action is set to srch.php


<font face="arial, helvetica" size="1">

$username = "XXXXXX";
$password = "XXXXXXX";
$database = "aXXXXXXXX";
$server  = "localhost";



$result = mysql_query("SELECT name, city, state, id FROM a2_bars WHERE name LIKE '".$_POST['term']."'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

printf('%s<br>%s<br><br>', $row[0], $row[1]);




#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 September 2006 - 01:34 PM

A blank page? That must be a PHP problem.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 jstu327

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 13 September 2006 - 01:47 PM

Hi a2bardeals,

Here are a few things I would check.

1. Make sure the method in search.html is set to POST because that is what you are using in your query.
2. If that is set to POST, then you can look at your query. Try putting an actual name in that you know exists in your database.


$result = mysql_query("SELECT name, city, state, id FROM a2_bars WHERE name LIKE 'Bob' "); (or whatever name might exist)

3. If that gives you a result, then the problem lies with your  WHERE name LIKE '".$_POST['term']."'

Try setting a variable to your search term and using it in your query accordingly.


$searchcontact = $_POST ['term'];

$result = mysql_query("SELECT name, city, state, id FROM a2_bars WHERE name LIKE '%$searchcontact%' ");

Also, I've found it helpful to put some html on the result page, or print out "ran successfully" after my queries during testing. That way, if the page comes up but there are no results, then you have query problems.  But, if the page is blank it's most likely a syntax error in your php somewhere.  In that case, just check your error logs.

Hope this helps you out!


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users