I looking to sum three values of the price field if selected.
$sql = "SELECT * FROM shoes
WHERE tray on tray.product_id = shoes.id";
$sth = mysql_query($sql);
$variety = mysql_fetch_array($sth)) {
echo'<div>
<p>'. $variety['name']. '</p>
<p class="price">'. $variety['price']. '</p>
<input name="price" type="checkbox" value="" />
</div>
<div>
<p>'. $variety['name']. '</p>
<p class="price">'. $variety['price']. '</p>
<input name="price" type="checkbox" value="" />
</div>
<div>
<p>'. $variety['name']. '</p>
<p class="price">'. $variety['price']. '</p>
<input name="price" type="checkbox" value="" />
</div>
}
if you notice each iteration will have a checkbox input and users can choose one or the three if they one. Now how can I sum how if user chooses more than one price?
In your form, you want PHP to treat your input as an array, so change your HTML like so-> add [] after the name.
Then in PHP just access the form variable name like you normally would and loop through the values and sum them.