Forums

PHP

This topic is locked

no results when I search my mysql database

Posted 20 Mar 2007 06:10:46
1
has voted
20 Mar 2007 06:10:46 Amanda Rojas posted:
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 = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

@mysql_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

Replies

Replied 15 Apr 2007 19:06:35
15 Apr 2007 19:06:35 student 101 replied:
That it is because there is no connection, or it is not connecting.
Replied 16 Apr 2007 16:55:40
16 Apr 2007 16:55:40 Alan C replied:
looks like you have the ip address as the host - you might have to configure your hosting account to allow that, you might find it works with localhost in there.

Reply to this topic