Simple Auto Calculate Function
Posted: Fri Apr 22, 2011 4:48 pm
I was looking to create a simple cart function off of PHP that multiples one fixed number and one variable (based on user input). So, basically the user enters 5 into the 'quantity' box and since there is only one item costing $20 it would automatically recalculate to $100 and show that in a 'total' box. I would appreciate any resources to help guide and show me more in-depth about it. Below I have provided my code, which is simple and I am sure not really close at all to what the final product needs to be.
Code: Select all
<html>
<body>
<form action="myform.php" method="post">
<p>Quantity: <input type="text" size=3 name="quantity" /></p>
</form>
</body>
</html>
<?php
$first_number = $quantity;
$second_number = 20;
$sum_total = $second_number * $first_number;
print ($sum_total);
?>