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>
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;
}
Re: Defaulting a Value of a Text Input Field