I have two parts to my question...
Part I:
I have a very basic search page (search.php) that pulls information from a MySQL database and displays it (results.php). If I enter something to search for...it works just fine and only displays the information requested. However, the problem arises if someone just hits "SEARCH" on the search without entering any information as then the results.php page shows EVERY entry in my database. Any ideas to fix that?
Here is what I am using...
Apache/1.3.31 (Win32)
PHP/5.0.0RC3
MySQL/3.23.38
And here is the code...
<?
mysql_connect("localhost","username","password");
mysql_select_db("database");
$search=$_GET["search"];
$result = mysql_query("SELECT * FROM table WHERE business LIKE '%$search%'");
while($r=mysql_fetch_array($result))
{
$business=$r["business"];
$address=$r["address"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];
echo "$business<br> <u>Address</u>: $address, $city, $state $zip<br><br>";
}
?>
Part II:
Right now, if there is a business without an address in my database, the results will still show "Address:" and a blank space where the address information should be. If there in no database information for address, is there a way to remove any mention of it in the search.php page?
Thanks in advance!