OK, so this is the last hurdle in the development side of my uni project, which is due VERY soon, I need to pick my daughter up from school in a minute (so I apologise for any delay in response - I assure you that I have not disappeared).
OK, so I am displaying various times (booking slots) to users which have been retrieved from the database. The user can then select the radio button relating the the time slot they wish to book. I have appended a counter so that the radio buttons each have a unique id. Upon clicking the 'book appointment' button the startTime
value and slotId
values need to be inserted into the bookings
table, along with the bookingId
from the availability
table and userId
from the users
table, based on the current SESSION
.
My problem is that as the radio buttons have different values, I am unsure how to define which radio button has been selected, and therefore how to write the query in which to insert the data relating to each unique radio button.
I know there is going to be an if statement in there somewhere, I am just not sure how to approach it, I have spent ages mulling this over, I am running out of time, the dog is driving me insane and my daughter means that time is very limited, so I really do appreciate any help or guidance offered :)
bookings.php `
}
?>
<!--Display available slots based on chosen date-->
<?php
if(isset($_POST['getDate'])){
$datepicker = strip_tags($_POST['datepicker']);
$datepicker = $DBcon->real_escape_string($datepicker);
$sql=("SELECT slotId, startTime, endTime, date FROM availability
WHERE date= '".$datepicker."'");
$query_s=mysqli_query($DBcon, $sql);
$row=mysqli_fetch_array($query_s);
if (!$row) {echo 'Error, No bookings available for this date,
please choose another';}
$counter = 1;
while ($row=mysqli_fetch_array($query_s)){
$id = 'slot_id'.$counter;
$counter++;
//echo '<div class="col-lg-3 col-md-3 col-sm-4 col-xs-6">';
?>
<table class="table-responsive">
<form class="form-bookings" method="post" action="<?php echo
htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<tbody>
<tr>
<td><?php echo $row['startTime'] ?></td>
<td><?php echo $row ['endTime'] ?></td>
<td><input type="radio" name="<?php echo ['slotId']?
>" id="<?php $id ?>" Value="<?php echo ['startTime']?>"></td>
<td><?php echo $id ?></td>
</tr>
</tbody>
<?php
}
}
?>
</form>
</table>
</div>
</div>
</div>`
Bookings Table columns are:
`bookingId
slotId
userId
startTime`