Skip to main content
Participant
March 20, 2007
Question

No results displayed when searching mysql

  • March 20, 2007
  • 11 replies
  • 716 views
Hello!
When I search mysql database using the following code all I get is a white page. No results indicating there was any error or indication that the database or table couldn't be selected. What am I doing wrong? Any and all help will be greatly appriecated!

Thank you,
Amanda

<?php

DEFINE ('DB_USER', 'manda');
DEFINE ('DB_PASSWORD', '*****');
DEFINE ('DB_HOST', '**.***.**.***');
DEFINE ('DB_NAME', 'products');

$dbc = @6688122_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

@6688122_select_db (DB_NAME_ OR die ('Could not select the database; ' .
mysql_error() );
$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM products WHERE item number LIKE '%$search%'");

//grab all the content
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns

$image=$r["title"];
$item number=$r["message"];
$title=$r["who"];
$description=$r["date"];
$price=$r["time"];

//display the row
echo "$image <br> $item number <br> $title <br> $description | $price <br>";
}

?>

---Of course I put n the correct info for the database connection, I just substitued it when I pasted the script. All the rest of the script is exactly what I used.
This topic has been closed for replies.

11 replies

Inspiring
March 20, 2007
SexyManda85 wrote:
> Hello!
> When I search mysql database using the following code all I get is a white
> page. No results indicating there was any error or indication that the database
> or table couldn't be selected. What am I doing wrong? Any and all help will be
> greatly appriecated!

When you get a blank page, it usually means that display_errors is
turned off. However, you have also used the error control operator (@)
in a couple of places, so error messages are also being suppressed by
your own script.

Check that display_errors is on. Also remove @ from your script.
However, I suspect the problem is here:

> @mysql_select_db (DB_NAME_ OR die ('Could not select the database; ' .
> mysql_error() );

You are using a non-existent constant, DB_NAME_. Remove the underscore
after NAME.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/