mtran
05-20-2006, 07:13 PM
Hi,
I have a simple form with radio button and a hidden field.
Item:
<form action="process.php" method="post">
<input name="item" type="radio" value="DVD"> DVD
<input name="item" type="radio" value="VHS">VHS
Quantity:
<input name="quantity" type="text">
<input name="cost" type="hidden">
</form>
I want to post the info to db and do simple calculation at the same time, but it doesn't work.
In process.php, I have:
<?php
$item = $_POST['item'];
$quantity =$_POST['quantity'];
$cost = $_POST['cost'];
if($item=="DVD")
$cost=$quantity*2;
else $cost=$quantity*1;
mysql_query ("INSERT INTO list (item,quantity,cost)
VALUES('$item','$quantity','$cost')",$connection);
?>
The item[DVD or VHS] and quantity are posted OK to db, but the cost is 0. What's wrong?
Thanks
I have a simple form with radio button and a hidden field.
Item:
<form action="process.php" method="post">
<input name="item" type="radio" value="DVD"> DVD
<input name="item" type="radio" value="VHS">VHS
Quantity:
<input name="quantity" type="text">
<input name="cost" type="hidden">
</form>
I want to post the info to db and do simple calculation at the same time, but it doesn't work.
In process.php, I have:
<?php
$item = $_POST['item'];
$quantity =$_POST['quantity'];
$cost = $_POST['cost'];
if($item=="DVD")
$cost=$quantity*2;
else $cost=$quantity*1;
mysql_query ("INSERT INTO list (item,quantity,cost)
VALUES('$item','$quantity','$cost')",$connection);
?>
The item[DVD or VHS] and quantity are posted OK to db, but the cost is 0. What's wrong?
Thanks