I have a form that I want to keep bringing up until a count matches the quantity. I'm not sure how to do this and everything that I try just fails. I'm listing my code to show that I'm bringing in some variables from another page. I'm just not sure where to place count code.
<?php
//start session
session_start();
if (isset($_POST['submitted'])) {
//Initialize error array
$errors = array();
//check for a serial number
if (empty($_POST['serial_no'])) {
$errors[] = 'You forgot the serial number.';
}
//Check for Total errors
if(empty($errors)) {
//add information to database
//include statement for database connectivity
include 'config.php';
// create a new mysqli object with default database
$connection = mysqli_connect($hostname, $username, $password, $dbname) or die ("Unable to connect");
// sql to INSERT a new record
$sql = "INSERT INTO production
(order_no, item_no, serial_no, price, fk_prodline_id)
values
('$_POST[order_num]', '$_POST[item_num]', '$_POST[serial_no]', '$_POST[price]', '2')";
//excute query
$result = mysqli_query($connection, $sql) or die ("Error in query: $sql. ".mysqli_error());
// close connection
mysqli_close($connection);
$qty_count = $count;
++$qty_count;
//redirect to serial number input form again
header("Location: horiz_entry_sn.php");
//if - else $errors
} else {
//report the errors
echo '<h1>Error!</h1>The following error(s) occurred: <br /><p>';
foreach ($errors as $msg) {
//print the errors message
echo "- $msg<br />\n";
}
echo '<p><p>Please go back and try again</p></p>';
}
//if - else statement isset
} else {
//recall session variables and assign to form variables
$price = $_SESSION['price'];
$order_num = $_SESSION['order_num'];
$item_num = $_SESSION['item_num'];
$quantity = $_SESSION['quantity'];
//$count = $_SESSION['count'];
?>
<script>
function toForm() {
document.horiz.serial_no.focus();
}
</script>
<html>
<head>
<title>Intranet</title>
</head>
<?php
echo $count;
?>
<body onload="toForm()" BGCOLOR=#FFFFFF topmargin="0" leftmargin="0"
marginheight=0 marginwidth=0 rightmargin=0 bottommargin=0>
<center>
<table border=0 cellpadding=0 cellspacing=0 width=100% vailn=top>
<!-- server side include leftside nav table -->
<!-- end of left side nav -->
<br>
<form name="horiz" method="post" action="horiz_entry_sn.php">
<div align="center">
<p> </p>
<table width="350" border="1" cellpadding="2" bordercolor="#000033"
style='border-collapse: collapse'>
<tr>
<td colspan="3" bgcolor="#3399FF"><div align="center"><strong>
<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Order Number: <?php echo $order_num; ?></font></strong></div></td>
</tr>
<tr>
<td colspan="3" bgcolor="#3399FF"><div align="center"><strong>
<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Item Number: <?php echo $item_num; ?></font></strong></div></td>
</tr>
<tr>
<td colspan="3" bgcolor="#3399FF"><div align="center"><strong>
<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Quantity: <?php echo $quantity; ?></font></strong></div></td>
</tr>
<tr>
<td>
<table border=0 cellpadding=3 cellspacing=0 width=99%>
<tr>
<td width=100%><font size="2" face="ARIAL, SANS-SERIF">
<p><strong>Serial Number:</strong><br>
<input type="text" name="serial_no" size=50 maxlength=75>
</p>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="submit" name="submit" value="submit">
<input type="hidden" name="submitted" value="true" />
<input type="hidden" name="price" value="<?php echo $price; ?>">
<input type="hidden" name="order_num" value="<?php echo $order_num; ?>">
<input type="hidden" name="item_num" value="<?php echo $item_num; ?>">
<input type="hidden" name="quantity" value="<?php echo $quantity; ?>">
<input type="hidden" name="qty_count" value="<?php echo $quantity; ?>">
</div></td>
</tr>
</table>
<?php
}
?>
I would also like to have the somewhere on the page show the count (i.e. 3 of 12). If anyone knows of any white papers on something like this, I would be very interested. Thanks for any help you may be able to provide.
A