I have created a reservations page for a restaurant website, with a form present to book a dinner reservation. It contains a dropdown box which allows the user to select the amount of people who will be dining in their party. It also contains a radio button to allow the user to select if they wish to be seated in the VIP area (Yes/ No).
Each person in the party should cost an extra £5 towards their booking fee and if they wish to be seated in the VIP area, they will be charged an additional £5. Once the form validation is successful, the user will be sent to a confirmation page, where the reservation details they have entered, will be displayed to them.
Currently I have a calculation present on the confirmation page of my website, which correctly calculates the party size costs, but my issue is that even if VIP area selection is "No", it is still adding on the £5 fee as if the user has selected "Yes".
Here is the relevant html code on my reservations page:
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['party'] = $_POST['party'];
}
if ( !empty($_POST['vip']))
$_SESSION['vip'] = $_POST['vip'];
?>
...
<strong>Select Party Size* :</strong>
<br>
<select name="party" id="party" value="<?php echo $party;?>">
<option value="">Please Select</option>
<option <?php if (isset($party) && $party=="1") echo "selected";?> value="1">1 Person (+£5)</option>
<option <?php if (isset($party) && $party=="2") echo "selected";?> value="2">2 People (+£10)</option>
<option <?php if (isset($party) && $party=="3") echo "selected";?> value="3">3 People (+£15)</option>
<option <?php if (isset($party) && $party=="4") echo "selected";?> value="4">4 People (+£20)</option>
<option <?php if (isset($party) && $party=="5") echo "selected";?> value="5">5 People (+£25)</option>
<option <?php if (isset($party) && $party=="6") echo "selected";?> value="6">6 People (+£30)</option>
<option <?php if (isset($party) && $party=="7") echo "selected";?> value="7">7 People (+£35)</option>
<option <?php if (isset($party) && $party=="8") echo "selected";?> value="8">8 People (+£40)</option>
<option <?php if (isset($party) && $party=="9") echo "selected";?> value="9">9 People (+£45)</option>
<option <?php if (isset($party) && $party=="10") echo "selected";?> value="10">10+ People (+£50)</option>
</select>
<strong> VIP area* : </strong> <br><br>
Yes (+£5) <input type="radio" name="vip" <?php if (isset($vip) && $vip=="Yes") echo "checked";?> value="Yes">
<br><span id="vip" class="error"><?php echo $vipErr;?></span><br>
No <input type="radio" name="vip" <?php if (isset($vip) && $vip=="No") echo "checked";?> value="No">
Here is the relevant calculation on the confirmation page:
<b>Total Reservation Costs: </b><br><br> £
<?php
if (isset($_SESSION['party']) && is_numeric($_SESSION['party'])) {
$party = (int)$_SESSION['party'];
$vip = isset($_SESSION['vip']) ? 5 : 0;
echo (($party * 5) + $vip);
}
?>
Does anyone know how I can enable the calculation to only add the additional £5 for VIP area seating if the user has selected "Yes"? I am new to web languages so any help will be appreciated. Thank you!