Forum Moderators: coopster
i have a page with a dynamic form wich extracts info from a table
id
title
price
on the form i have a repeat all which will display the title, price and id of each item, and a text box which i added id= <?php $id; ?> and also the internal name this text box will ask the user for an amount what i need to do is that this amount be multiply by the price and then do a sum of all of it, i have manage to show the amount in a $_POST[$id] but i have no idea how to do the multiplication and then the sum, i donīt need to save the data from the post in a database just show the person that is using this what he has to pay if he adds X amounts of products, i was thinking on using arrays but im still to new to php trying to learn any helps is appreciated
Thanks
<form action="index.php" method="POST">
Item1<input type="text" name="item1"><br>
Item2<input type="text" name="item2"><br>
Item3<input type="text" name="item3"><br>
<input type="submit" value="submit">
</form>
<inside your action script>
$total = 0;
foreach(array_keys($_POST) as $key){//assigns variables
$itemId = str_replace("item", "", $key); //takes off the "item" to reveal the item id
$amount = $_POST[$key];//checks for invalid data - i.e not integer inputs
//query for price of item
$result = mysql_query("SELECT price FROM myItemsTable where id = ".$itemId);
$row = mysql_fetch_assoc($result);
$price = $row['price'];//total price for this item
$subTotal = $price*$amount;//grant total
$total+=$total;
}