I have a two part entry form (parent form where I get the Batch Number) and it calls a javascript popup window so I can enter in all the units of a product that belongs to the Batch Number that was selected. Everything works except the while loop. Apparently the loop works... but it scrolls through the entire while loop after the first unit is entered into the batch which defeats the purpose of having a loop to regulate the quantity of product that is to be in that batch number.
Here is my code which I'm having issues with. I need to be able to enter in the first unit into the selected batch, the screen refreshes (which it does) then be able to enter the second unit BUT the WHILE LOOP needs to count against ever new entry not just the first one. My second unit entry is placed in the database but I need the while loop as the Quantity restrictor for each batch (in each batch there is a specified quantity of product)... so if the QTY is 3 I can only enter 3 units into the database... now I can enter an infinite amount of product since the loop exhausted itself on the first entry and I have no stops in the loop so it rolls on.
Any ideas???? 😕 Here is the code:
<head>
<title>Receiving</title>
</head>
<?php
if (isset($_GET['param1']) && !empty($_GET['param1'])){
$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];
$1Num=$sql['1Num'];
$ModelType=$sql['ModelType'];
$Sku=$sql['OEMSku'];
$Card=$sql['CardType'];
$growit = 0;
while ($growit <= $Qty) {
@mysql_query("INSERT IGNORE INTO `recv` (`ProdNum`, `SerNum`, `BatchNum`, `ModelType`, `ModelSku`, `1Num`,`CardType`, `DateRecv`) VALUES ('" . $_POST['ProdNum'] . "', '" . $_POST['SerNum'] . "', '$Batch', '$ModelType','$Sku','$1Num', '$Card', Now())") or die(mysql_error());
@mysql_query("DELETE FROM `recv` WHERE `ProdNum` = 0");
$growit = $growit + 1;
$Countdown = $Qty - $growit + 1;
echo "<br>Count: $growit | Remaining: $Countdown\n";
}
mysql_close($con);
}
?>
<body bgcolor="#CCCCCC">
<P>
<form method="post" name="Recv" action="testrecv1.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">Serial Number: </td>
<td bgcolor="#cccccc"><input name="SerNum" id="SerNum" type="text"></td>
</tr>
<tr>
<td bgcolor="#ffcc66" width="135">Prod Number:</td>
<td bgcolor="#cccccc" width="300"><input name="ProdNum" id="ProdNum" type="text"></td>
</tr>
<tr>
<td> </td>
<td><input value="submit" name="submit" type="submit"></td>
</tr>
</tbody>
</table>