All,
I have a form that is for bulk receiving but I need to add some additional validation checking. However when I do, I cannot get the form to reload after the first piece of data is collected and the data is not written to the database... for part two - writing to the database I can figure that out, since I believe I know the problem... but I cannot figure out how to accomplish the form to reload. here is the code I have:
<?php
$newline = "<br />";
$space =" ";
if (isset($_GET['param1']) && !empty($_GET['param1'])){ //'param1' is a variable being passed from the parent form.
$BatchNumData=$_GET['param1'];
echo "Your Batch Number is:\n$BatchNumData"; }
elseif ($_SERVER['REQUEST_METHOD'] == 'POST'){
$BatchNumData=$_POST['param1'];
echo "Your Batch Number is:\n$BatchNumData";
// Connect to mysql database
$con = mysql_connect("localhost","user","XXXX") or die('Connection: ' . mysql_error());;
mysql_select_db("test", $con) or die('Database: ' . mysql_error());
// Insert form values into database
$sql = mysql_fetch_array(mysql_query("SELECT * FROM `batch` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error());
// SELECT THE DATA TO BE COPIED
$Batch=$sql['BatchNum'];
$Qty=$sql['Qty'];
$CodeNum=$sql['CodeNum'];
$ModelType=$sql['ModelType'];
$Sku=$sql['OEMSku'];
$Card=$sql['CardType'];
$growit = 0;
while ($growit <= $Qty) {
echo "You are on \n$growit of $Qty.$space to Receive for Order Number:\n$Batch.".$newline;
$prod=$_POST['ProdNum'];
$checkit = mysql_fetch_array(mysql_query("SELECT * FROM `recv` WHERE `ProdNum` = $prod")) or die(mysql_erro());
$bounce=$checkit['ProdNum'];
$badbatch=$checkit['BatchNum'];
$badser=$checkit['Sernum'];
$badsku=$checkit['ModelSku'];
$baddate=$checkit['DateRecv'];
$badtype=$checkit['ModelType'];
$badrts=$checkit['CodeNum'];
$badcard=$checkit['CardType'];
if ($prod == $bounce && $Batch != $badbatch) {
?>
<script language="JavaScript">
alert("This Unit Appears to be a Bounce. The original record has been transferred to the History Table.");
window.close();
</script>
<?php
//Insert the old record of the IMEI into the recvhist table.
@mysql_query("INSERT INTO `recvhist` (`ProdNum`, `BatchNum`, `ModelType`, `ModelSku`, `CodeNum`,`CardType`, `DateRecv`, `BounceDate`) VALUES ('$bounce', '$badbatch', '$badtype','$badsku','$badrts', '$badcard', '$baddate', Now())") or die(mysql_error());
//delete the original record of the bounced IMEi from the recv table.
@mysql_query("DELETE FROM `recv` WHERE `ProdNum` = $bounce");
//Allow the entry of the new IMEI into the recv table.
@mysql_query("INSERT IGNORE INTO `recv` (`ProdNum`, `BatchNum`, `ModelType`, `ModelSku`, `CodeNum`,`CardType`, `DateRecv`) VALUES ('" . $_POST['ProdNum'] . "', '$Batch', '$ModelType','$Sku','$CodeNum', '$Card', Now())") or die(mysql_error());
@mysql_query("DELETE FROM `recv` WHERE `ProdNum` = 0");
$addit = mysql_fetch_array(mysql_query("SELECT * FROM `recv` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error());
}
if ($prod != $bounce) {
@mysql_query("INSERT IGNORE INTO `recv` (`ProdNum`, `BatchNum`, `ModelType`, `ModelSku`, `CodeNum`,`CardType`, `DateRecv`) VALUES ('" . $_POST['ProdNum'] . "', '$Batch', '$ModelType','$Sku','$CodeNum', '$Card', Now())") or die(mysql_error());
@mysql_query("DELETE FROM `recv` WHERE `ProdNum` = 0");
}
mysql_close($con);
$growit=$growit +1;
}
}
?>
<body bgcolor="#CCCCCC">
<P>
<BODY OnLoad="placeFocus()">
<form method="post" name="Recv" action="imeirecvbounce.php"><font color="#000080" face="Arial">
<input type="hidden" name="param1" value="<?php echo $BatchNumData; ?>" />
<table border="0" cellpadding="3" cellspacing="2" width="400">
<tbody>
<tr style="color: rgb(255, 255, 255); font-weight: bold;">
<td colspan="2" bgcolor="#000000"><span class="style1">Receiving Module</span></td>
</tr>
<tr>
<td bgcolor="#ffcc66" width="135">IMEI Number:</td>
<td bgcolor="#cccccc" width="300"><input name="ProdNum" id="ProdNum" type="text" maxlength=15 onkeyup="moveOnMax(this,'submit')"/ ></td>
</tr>
<tr>
<td> </td>
<td><input value="submit" name="submit" type="submit" ></td>
</tr>
</tbody>
</table>
<center><form method="post">
<input type="button" value="Close Window"
onclick="window.close()">
</form>
</center>
Now this is before I have added all my validation... I did ad one where if there is a ProdNum that already exists in the database notify the user that this is a pre-existing repair called a Bounce. It works, and when I enter in a test prod num that is a bounce it does as expected... however, if the number I enter in is a new number, it will not recycle the form and add the data into the database... I think I have that portion worked out, but I need for the form to reload until the proper quality is reached.
I decided to use a WHILE Loop against the QTY of the overall order, but it does not seem to work correctly... but it could be working, and the INSERT command is the problem... just not sure at this point.
I'm presently trying each section separately to determine the location of my troubles, but I just need to understand if I have the WHILE loop syntax correct, and why it will not reload my form... since it may be how I have it setup... not sure.