Hey guys and gals,
I've been coding this page for the last few hours and it's starting to drive me nuts. All works perfectly except it will always enter the data into the database. Even when it shouldn't. Can anybody please let me know how to just make this line work right:
If($serial!=$serials and $asset!=$assets) {
I have one thing to ask. If you're going to suggest a different way to go about doing the duplicate check (though I'd like to keep it like this) please at least supply some code so I know what's going on instead of confusing me more with hints. Thanks.
<?
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'];
$po = $_POST['po'];
$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="-";
}
$query="SELECT * FROM assets";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$serials=mysql_result($result,$i,"serialNum");
$assets=mysql_result($result,$i,"assetNum");
//Check if the data entered is a duplicate
if($serial==$serials) {
printf("<TR ALIGN=center><TD>The serial number entered already exists</TD></TR>");
if($asset==$assets) {
printf("<TR ALIGN=center><TD>The asset number entered already exists</TD></TR>");
}
}
++$i;
}
//If the data is not a duplicate, insert it into the database
If($serial!=$serials and $asset!=$assets) {
$query = "INSERT INTO assets SET serialNum = '$serial',assetNum = '$asset',itemName = '$name',location = '$location',po = '$po',entryDate = '$doe',warranty = '$warranty'";
mysql_query($query);
printf("<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=="") {
printf("<TR ALIGN=center><TD>You must enter a name and location</TD></TR>");
}
include("footer.inc");
?>