I have no idea how to calculate total price of this subjects using php. help me with it.
<div id="mydiv" style="display:none">
<input type="checkbox" name="subject[]" value="biology">biology<br>
<input type="checkbox" name="subject[]" value="physics">physics<br>
<input type="submit" value="Calculate" name="submit" class="wpcf7-submit">
</div>
<div id="mydiv1" style="display:none">
<input type="checkbox" name="subject[]" value="maths">maths<br>
<input type="checkbox" name="subject[]" value="science">science<br>
<input type="submit" value="Calculate" name="submit" class="wpcf7-submit">
</div>
I want to calculate price total of this checkboxes and store it in database with its names using php
php part
if(isset($_POST['subject']))
{
$classes=$_POST['subject'];
$prices = array(
'biology' => 60,
'physics' => 200
);
$sum = array();
$getkeys = array_keys($_POST);
foreach($prices as $key => $value)
{
if(in_array($key, $getkeys)) $sum[] = $value;
}
$ar=array_sum($sum);
echo $ar;
if($classes)
{
$subject = implode(',', $ar);
$query="INSERT INTO feedetails (subjects,price) VALUES ('".$subject."','".$price."')";
if(mysqli_query($conn,$query))
{
echo ("<SCRIPT LANGUAGE='Javascript'>
window.alert('Your fee has been updated.Please proceed to pay.');
window.location.href='payment.php';
</SCRIPT>");
}
}