I have this HTML page wherein there are checkboxes with different numerical values and I've set up a PHP file to compute the sum of checked checkboxes (HTML then when the user clicks the submit button, the page will be redirected to the PHP file). What I'm trying to do is, based on the sum, can I use if else statements where I'll set a range of possible sums (i.e. 1-100, 101-500) and the ranges will have a correspnding values again. (The concept behind is, I'm doing this carbon footprint thing, and for 5k-10kg consumption of CO2, the equivalent number of earths needed to sustain your living is 2.50.)
HTML
<form action="index.php" method="post"/>
<h3>Laundry</h3>
<label><input type="checkbox" name="checkbox[]" id="laundry1" class="sum" value="46" data-toggle="checkbox">Fabric Conditioner Pure 2L</label><br>
<label><input type="checkbox" name="checkbox[]" id="laundry2" class="sum" value="44" data-toggle="checkbox">Fabric Conditioner Blue 4L</label><br>
<label><input type="checkbox" name="checkbox[]" id="laundry3" class="sum" value="650" data-toggle="checkbox">Laundry Liquid 1.5L</label><br>
PHP (to sum the checked checkboxes)
<?php
if($_POST){
$val = 0;
foreach($_POST['checkbox'] as $checkbox){
$val += $checkbox;
}
echo $val;
}
?>
What I'm trying so far for the ifelse statements
<?php
if ($val >= 1 && $val <= 100) {
echo "0.02";
}
if else ($val >= 101 && $val <= 500) {
echo "0.10";
}
?>
I'm currenty stucked right now and any help would be appreciated!
Aucun commentaire:
Enregistrer un commentaire