|
-
May 19th, 2008, 08:53 PM
#1
Defaulting a Value of a Text Input Field
I've got the following script. It allows a user to input a quantity, then the new price is updated. But there seems to be a code error (in that is doesn't update for the new price).
Can anyone see where the error might be?
Code:
<?php
if(isset($_POST["quantity"]))
$quantity = settype($_POST["quantity"], "integer");
else
$quantity = 1;
$item_price = 10.99;
printf("%d x item = $%.2f",
$quantity, $quantity * $item_price);
?>
<FORM ACTION="buy.php" METHOD=POST>
Update quantity:
<INPUT NAME="quantity" SIZE=2
value =<?php echo $quantity;?>">
<INPUT TYPE=SUBMIT VALUE="Change quantity and re-calculate price">
</FORM>
Last edited by PeejAvery; May 28th, 2008 at 07:59 AM.
Reason: Added code tags.
-
May 21st, 2008, 11:29 AM
#2
Re: Defaulting a Value of a Text Input Field
settype() is being used incorrectly. It should be:
Code:
if(isset($_POST['quantity'])) {
$quantity = $_POST['quantity'];
if(!settype($quantity, 'integer'))
$quantity = 1;
} else {
$quantity = 1;
}
-
May 23rd, 2008, 12:53 AM
#3
Re: Defaulting a Value of a Text Input Field
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|