jonahpup,
Here is something that should work, there are better ways to do it, but its pretty easy to understand and see what is happening.
I used mysql_num_rows() to get the number of rows that the query found, if it is greater than (or equal to) 1, then it will display the voucher information, otherwise it must be an invalid voucher.
I also included mysql_real_escape_string. You should read up on SQL Injection.
I am unsure if I had used that correctly, as I use M$ SQL (at work, not my idea), so it takes things in a little differently.
I also had the form post to itself, so nomatter what you name the script it should work.
Feel free to ask questions if you need.
Good Luck
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Voucher Management</title>
<link rel="stylesheet" type="text/css" href="../styles/main.css" />
</head>
<body>
<div id="main">
<h1 style="text-align:center">Voucher Management</h1>
<div style="border: 1px dashed black; padding: 1.5em">
<h3>Lookup Voucher Details </h3>
<form method="post" name="voucherForm" id="voucherForm" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="100%">
<tr>
<td width="30%"><p>Voucher Number: <input type="text" name="voucherNumber" /></p></td>
<td width="40%"></td>
<td width="30%"><p class="instruction">Enter the voucher number that you want to look up</p></td>
</tr>
<tr>
<td><input name="submit" type="submit" Value="Lookup Voucher" /></td>
<td></td>
<td><p class="instruction">Click here to search for the voucher number you have entered</p></td>
</tr>
</table>
</form>
<?php
$vouchernum = $_REQUEST['voucherNumber']; // Get the voucher number...
if (isset($vouchernum)) { // If the voucherNumber has been passed then display the following:
// I only want this part to show, if submit has been clicked and if a voucher number exists
$con = mysql_connect("localhost", "uname", "pwd");
if (!$con)
{
die ('Could not connect: ' .mysql_error());
}
mysql_select_db ("dbase", $con);
$result = mysql_query("SELECT * FROM vouchers WHERE voucherID='".mysql_real_escape_string($_POST['voucherNumber'])."'");
if (mysql_num_rows($result) >= 1) { // Wow! We have found one (or MORE??)
echo "<table border='1'>
<tr>
<th>Voucher Number</th>
<th>Name</th>
<th>Date Issued</th>
<th>Expiry Date</th>
<th>Conditions</th>
<th>Voucher Issued By</th>
<th>Redeemed (Y/N)</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['voucherID'] . "</td>";
echo "<td>" . $row['issuedName'] . "</td>";
echo "<td>" . $row['issuedDate'] . "</td>";
echo "<td>" . $row['expiryDate'] . "</td>";
echo "<td>" . $row['conditions'] . "</td>";
echo "<td>" . $row['issuedBy'] . "</td>";
echo "<td>" . $row['redeemed'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else { // if there is less than one, it must not exist
echo "Invalid Voucher Number, Please Try Again";
} // end if mysql_num_rows()
mysql_close($con);
} // end if (isset($vouchernum)
?>
</div>
</div>
</body>
</html>