I am making an ecommerce-like website.
I am trying to make a price calculator so customers can count total price for their product specification.
The specification variable is taken from a database, so the form is kind of dynamic.
I need to calculate the base price + (specification + specification + specification ) * quantity. you could also suggest me to choose from PHP / AJAX
Here is the form
<form method="GET" action="../action/calculate.php">
<?php
include "../connect.php";
$slug = $_GET['slug'];
$sql="SELECT * FROM product,options WHERE options.product_id = product.id AND product.slug = '$slug'";
$result = $conn->query($sql);
while ($data = $result->fetch_assoc()){
$id = $data['id'];
echo "
<div class='form-group'>
<label>".$data['options_title']."</label>
<select name='".$data['options_title']."' class='form-control operator'>
"
?>
<?php
$options_id = $data['options_id'];
$sql2="SELECT * FROM options_value WHERE options_id = '$options_id' ";
$result2 = $conn->query($sql2);
while ($data2 = $result2->fetch_assoc()){
echo "<option value='".$data2['price_add']."'>".$data2['options_value_title']." +IDR ".number_format($data2['price_add'], 0, ',', '.')."</option>";
}
?>
<?php echo "
</select>
</div>
";
}
?>
<div class='form-group'>
<label>Jumlah</label>
<input type="number" name="jumlah" min="1" value="1" class="form-control">
</div>
<button type="submit" class="btn btn-success px-5 font-weight-bold">Lanjut</button>
</form>
$bahan = $_GET['bahan'];
$laminating=$_GET['laminating'];
$jumlah=$_GET['jumlah'];
echo ($bahan + $laminating) * $jumlah;