Ok, I'm not sure if any of this is right but for some reason it keeps saying:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/html/enter.php on line 32
All I'm trying to do is check for a duplicate serial number. Can anybody tell me if I'm going about it the wrong way or if its my poor syntax?
<?
include("header.inc");
include("menu.inc");
include ("details.inc");
//Post all values into variables from the enterForm.php form
$serial = $_POST['serial'];
$asset = $_POST['asset'];
$name = $_POST['name'];
$location = $_POST['location'];
$description = $_POST['description'];
$doe = date("F j, Y");
$warranty = $_POST['warranty'];
//Check to see if the user left the item name blank
if($name!="") {
//If fields are left blank, fill them with hyphons
if($serial=="") {
$serial="-";
}
if($asset=="") {
$asset="-";
}
if($description=="") {
$description="-";
}
if($warranty=="") {
$warranty="-";
}
While ($rs = mysql_fetch_array($result)) {
if ($rs['serialNum']==$serial) {
printf("The serial number entered already exists");
}
}
if ($rs['serialNum']!=$serial) {
//Insert the data into the database and display to the user that this has been done
$query = "INSERT INTO assets SET serialNum = '$serial',assetNum = '$asset',itemName = '$name',location = '$location',description = '$description',entryDate = '$doe',warranty = '$warranty'";
mysql_query($query);
}
?>
<TR ALIGN="CENTER">
<TD>The data has been entered successfully</TD>
</TR>
<?
}
//If the user left the item name blank, infor the user it is required to complete this field
Elseif($name=="") {
?>
<TR ALIGN="CENTER">
<TD>You must enter a name and location</TD>
</TR>
<?
}
include("footer.inc");
?>