Hi All,
Have a script that uses a post method and then searches through a mysql db.
<html>
<title>Reseller Locater</title>
<body>
<form method="post">
Please enter the postcode you wish to search by.<br><br>
Post Code: <input type="text" name="lookup" size="10"><br>
<br>
<input type="submit" value="Search" name="submit">
</form>
<hr><br>
<?
mysql_connect('localhost','root');
@mysql_select_db('dbname')or die("Unable to connect to selected database.");
$lookup=$_POST['lookup'];
if (submit) {
$query="Select * from company where postcode LIKE '%$lookup%'";
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num>0){
echo "<center>The following companies match the postcode <b>$lookup</center></b><br>";
$i=0;
while($i<$num){
$company=mysql_result($result,$i,"company");
$address=mysql_result($result,$i,"address");
$address2=mysql_result($result,$i,"address2");
$county=mysql_result($result,$i,"county");
$postcode=mysql_result($result,$i,"postcode");
$tel=mysql_result($result,$i,"tel");
$fax=mysql_result($result,$i,"fax");
$web=mysql_result($result,$i,"web");
//$first=mysql_result($result1,$i,"first");
echo "<b> $company</b><br><b> $address</b><br><b> $address2</b><br><b> $county</b><br><b>
$postcode</b><br><b> $tel</b><br><br>";
++$i;
}
}
else
echo"<center>There were no companies that matched the postcode <b>$lookup</b></center><br>";
}
echo"";
?>
</body>
</html>
What I need to have, is if there is no postcode entered, then the output is blank, if a postcode is entered then the db searches and gives results based on its findings.
I have the latter two parts working, however I need the first part - a blank screen if nothing is entered.
Does this make sense? I think this will be easy to sort out, just not sure how.
Thanks.