i have the following search form and script
it works ok but if I hit the search without filling anything on the search box it prints all records whereas i would like it to return No record found. what am I doing wrong?
<?
session_start();
if(!session_is_registered(myusername)){
header(“location:main_login.php”);
}
?>
<html>
<body>
Login Successful
</body>
</html><html>
<head>
<meta name=”GENERATOR” content=”Microsoft FrontPage 5.0″>
<meta name=”ProgId” content=”FrontPage.Editor.Document”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>Search database</title>
<meta name=”Microsoft Theme” content=”indust 000, default”>
<meta name=”Microsoft Border” content=”tlb, default”>
</head>
<body>
<p> <form method=”post” action=”results.php” target=”_blank”>
<div align=”center”>
<table border=”1″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td bordercolor=”#000000″>
<p align=”center”>
<select name=”metode” size=”1″>
<option value=”consignee”>Consignee</option>
<option value=”datefcrissued”>Date FCR Issued</option>
<option value=”fcrnumber”>FCR Number</option>
</select>
<input type=”text” name=”search” size=”25″ value=””> <br>
Search : <input type=”submit” value=”Go!!” name=”Go”></p>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
————————————————————————–script
<html>
<head>
<meta name=”GENERATOR” content=”Microsoft FrontPage 5.0″>
<meta name=”ProgId” content=”FrontPage.Editor.Document”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>id</title>
<meta name=”Microsoft Theme” content=”indust 000, default”>
<meta name=”Microsoft Border” content=”tlb, default”>
</head>
<body>
<center>
<table border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td width=”50″><b>DRN</b></td>
<td width=”100″><b>Loading Date</b></td>
<td width=”100″><b>L/O Number</b></td>
<td width=”100″><b>Ginnery</b></td>
<td width=”100″><b>Origin country</b></td>
<td width=”100″><b>Supplier</b></td>
<td width=”150″><b>Delivery Number</b></td>
<td width=”100″><b>Lot Number</b></td>
<td width=”100″><b>No of Bales</b></td>
<td width=”100″><b>Type</b></td>
<td width=”100″><b> Truck Reg. No.</b></td>
<td width=”100″><b>Container No</b></td>
<td width=”100″><b>FCR Number</b></td>
<td width=”100″><b>FCR Date</b></td>
</tr>
<tr>
<td>
<?php
$hostname = “88888888888889”; // The Thinkhost DB server.
$username = “888888888888”; // The username you created for this database.
$password = “i888888888”; // The password you created for the username.
$usertable = “cotton”; // The name of the table you made.
$dbName = “livercot”; // This is the name of the database you made.
//Get the connection handle
$conn = mysql_connect($hostname, $username, $password) OR DIE(“DB connection failed”);
//Add the connection param
mysql_select_db( “$dbName”,$conn) or die( “Unable to find database”);
//error message (no record message)
$ERR = “Sorry we can’t find that record.”;
//query details table begins
$XX = “No Record Found”;
$query = mysql_query(“SELECT * FROM cotton WHERE $metode LIKE ‘%$search%’ LIMIT 0, 30”);
// if > 0 rows are returned
if(mysql_num_rows($query))
{
while ($row = mysql_fetch_array($query))
{
//These variables don’t need to be set… See below
$variable1=$row[“documentsreceivednote”];
$variable2=$row[“loadingdate”];
$variable3=$row[“loadingorderno”];
$variable4=$row[“ginnery”];
$variable5=$row[“origincountryofgoods”];
$variable6=$row[“supplier”];
$variable8=$row[“deliverynumber”];
$variable9=$row[“lotnumber”];
$variable10=$row[“noofbales”];
$variable11=$row[“type”];
$variable12=$row[“truckregnumber”];
$variable13=$row[“containernumber”];
$variable14=$row[“fcrnumber”];
$variable15=$row[“fcrdate”];
//table layout for results
print (“<tr>”);
print (“<td>” . $row[“documentsreceivednote”] . “</td>”);
print (“<td>” . $row[“loadingdate”] . “</td>”); //Add the variables with concatenation
print (“<td>” . $row[“loadingorderno”] . “</td>”);
print (“<td>” . $row[“ginnery”] . “</td>”);
print (“<td>” . $row[“origincountryofgoods”] . “</td>”);
print (“<td>” . $row[“supplier”] . “</td>”);
print (“<td>” . $row[“deliverynumber”] . “</td>”);
print (“<td>” . $row[“lotnumber”] . “</td>”);
print (“<td>” . $row[“noofbales”] . “</td>”);
print (“<td>” . $row[“type”] . “</td>”);
print (“<td>” . $row[“truckregnumber”] . “</td>”);
print (“<td>” . $row[“containernumber”] . “</td>”);
print (“<td>” . $row[“fcrnumber”] . “</td>”);
print (“<td>” . $row[“fcrdate”] . “</td>”);
print (“</tr>”);
}
}
else
{
print (“$ERR”);
}
//end
?>
</body>
</html>
?