Newbie trying to figure out how to use a form correctly
am 11.11.2007 22:56:30 von pnberryHello,
I'm creating a form for data entry. Specifically, data entry via a
digital scale for a POS like system (using a serial interface or using
manual entry via a keyboard which is all I am doing now - I'll worry
about the scale once I get this problem sorted out...).
Anyway there is a quantity (weight in pounds) field, a tare weight
field, a price per pound field and a total charges field. I type in
values to the quantity and tare weight fields and there is a default
price per pound rate. When I press the submit ("Update") button the
total charges field displays the price per pound *(quantity - tare
weight) . All this is simple enough and it works BUT it takes TWO
clicks of the submit button to display any changes in the total
charges field when I change either the quantity or tare weights. What
am I missing or mis-understanding here? How would I make it so all it
takes is one click of the submit ("Update") button to display the
correct amount in the amount_due field?
Hope this makes sense. Thanks for any help or input, I really
appreciate it.
Paul
Here's my form code:
session_start();
include ("../settings.php");
$db = mysql_connect("$server", "$username", "$password");
mysql_select_db("$database",$db);
print '';
print '
#Sticky data
#Custom Date
if (!isset($_SESSION['custom_date'])) {
$_SESSION['custom_date'] = date('Y-m-d');
}
#Recycle values
if (!isset($_SESSION['recy_quantity'])) {
$_SESSION['recy_quantity'] = 0;
}
$_SESSION['recy_quantity'] = $_GET['recy_quantity'];
if (!isset($_SESSION['recy_tare'])) {
$_SESSION['recy_tare'] = 0;
}
$_SESSION['recy_tare'] = $_GET['recy_tare'];
#Trash values
if (!isset($_SESSION['trsh_quantity'])) {
$_SESSION['trsh_quantity'] = 0;
}
$_SESSION['trsh_quantity'] = $_GET['trsh_quantity'];
if (!isset($_SESSION['trsh_tare'])) {
$_SESSION['trsh_tare'] = 0;
}
$_SESSION['trsh_tare'] = $_GET['trsh_tare'];
#Main entry form body
print " \"transaction_form\">";
print '
'; | Date   | ';value="now" align=left> Now | YYYY-MM-DD | ';|||
---|---|---|---|---|---|---|
'; | Custom | ';\"$_SESSION[custom_date]\"> | ";||||
Item Name | ';Quantity | ';![]() th>'; print ' | Tare Wt | ';$ Per Unit | ';Amount Due | ';![]() th>'; print ' |
Recyclables - simple rate  | '; #WHAT, the item'; #Quantity field | '; | value="' . $_SESSION['recy_tare'].'"> | '; #Tare weight field$ | '; #Price per pound\$$_SESSION[recy_amount_due] | "; #Amount due field'; |
Trash  | '; #WHAT, the item name'; #Quantity field | '; | value="' . $_SESSION['trsh_tare'].'"> | '; #Tare weight field$ | '; #Price per pound\$$_SESSION[trsh_amount_due] | "; #Amount due field'; |
print '';
print '';
print '';
#Form processing
if (isset($_GET['recy_quantity'])) {
$_SESSION['recy_amount_due'] =
$_GET['recy_price']*($_GET['recy_quantity'] - $_GET['recy_tare']);
}
if (isset($_GET['trsh_quantity'])) {
$_SESSION['trsh_amount_due'] =
$_GET['trsh_price']*($_GET['trsh_quantity'] - $_GET['trsh_tare']);
}
?>