My last If statement which is supposed to display if no records are found on the search, doesn't seem to be working. My only conclusion is that it might be conflicting with the first IF statement that checks to make sure that there is data being passed from the form. If thats the problem, How do I fix it? And if not, is it a syntax error somewhere? I have been working on this one problem for 3 hours now with no solution. Please Help! Thanks in advance. --joey
<?
//error message (no data in the form fields)
$missingdata = "You have not entered search details. Please <a href=\"/company.html\">go back</a> and try again.";
if (!$companyname)
{
print ("$missingdata");
exit;
}
//Connection Variables
$dbhost = "localhost"; // Usually localhost.
$dbuser = "root"; // If you have no username, leave this space empty.
$dbpass = ""; // The same applies here.
$dbname = "chamber"; // This is the main database you connect to.
$usertable = "members"; // This is the table you made.
//Connect
$db = mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db( "$dbname",$db) or die( "Unable to select database");
//error message (not found message)
$XX = "No Record Found";
//Query
$query = mysql_query("SELECT * FROM $usertable WHERE companyname LIKE '%$companyname%' LIMIT 0, 30 ");
while ($myrow = mysql_fetch_array($query))
{
print ("\n<b>Company Name:</b> ");
print ("\n<a href=\"http://");
echo "$myrow[web]";
print ("\">");
echo "$myrow[companyname] ";
print ("</a>");
print ("\n<b>Name:</b> ");
echo "$myrow[firstname] ";
echo "$myrow[lastname]<BR>";
}
//below this is the function for no record!!
if (!$companyname)
{
print ("$XX");
}
end
?>