I have a simple form which allows a visitor to enter a invoice number. When they submit the form the invoice number is passed to a PHP script which looks it up in a mysql data base and returns other data from the same row as the entered invoice number.
If a visitor enters an invoice number that isn't in the table, I would like to display a message to that effect. I have tried al kinds of php "if" statements using functions ranging from "isset()" to "empty()" but none work. What is the simple way to accomplish my goal? Here is the PHP code I currently have:
<?php
include "config.php";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<html>
<head>
<title>Customer Invoice</title>
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
?>
<center>
View Invoice
<form action="" method="post">
Please enter your invoice number and then press "View".<br />
<input type="text" name="invoice" size="5">
<input type="submit" name="submit" value="View">
</form>
<br />
<br />
<br />
Admin Login
</center>
<?php
} else {
$invoice = mysql_real_escape_string($_POST['invoice']);
$result = mysql_query("SELECT * FROM invoices WHERE invoice='" . $invoice . "'");
while($row = mysql_fetch_array($result))
{
echo "<center>Invoice # " . $row['invoice'] . "</center>";
echo "<center>" . $row['name'] . "</center>";
echo "<center>" . $row['date'] . "</center><br /><br />";
echo "Hours: " . $row['hours'] . "<br />";
echo "Rate: $" . $row['rate'] . "/hr<br />";
echo "Labor Charge: $" . ($row['hours'] * $row['rate']) . "<br /><br />";
echo "Hardware: " . $row['h1'] . " -$" . $row['c1'] . "<br />";
echo "Hardware: " . $row['h2'] . " -$" . $row['c2'] . "<br />";
echo "Hardware: " . $row['h3'] . " -$" . $row['c3'] . "<br />";
echo "Parts Charge: $" . ($row['c1'] + $row['c2'] + $row['c3']) . "<br /><br />";
echo "Total Due: $" . $row['total'] . " Paid: $" . $row['paid'] . " Balance Due: $" . ($row['total'] - $row['paid']) . "<br /><br />";
echo "Notes: " . $row['notes'];
echo "<br /><br />END OF INVOICE<br />";
echo "Click here to search again.";
}
}
?>
</body>
</html>
-Ryan Adams
http://RyanTAdams.com