I have generated a table from a query and at the end of each row in the table there is a 'book' button. Once this button is selected, a modal asking the user to enter their ID is shown. Once the user enters their ID, a button is clicked and the ID is checked against the database.
What I would like to do is when the button is clicked within the modal have the selected row data and the members ID inserted into the database table. I'm getting confused on how I can get the selected row data after the modal is shown.
An image of php table:
Code for index.php
<table class="table table-bordered">
<tr>
<th width="10%">Class</th>
<th width="35%">Date</th>
<th width="40%">Time</th>
<th width="10%">Location</th>
<th width="5%">Book</th>
</tr>
<?php
while ($row = mysqli_fetch_array($sql)){
$classdescription = $row["class_description"];
$date = $row["date"];
$start = $row["startTime"];
$area = $row["area_description"];
?>
<tr>
<td><?php echo $classdescription?></td>
<td><?php echo $date?></td>
<td><?php echo $start?></td>
<td><?php echo $area?></td>
<td><input type="button" data-toggle="modal" data-target="#myModal" value="Book" name="book"/>
</td>'
</tr>
<?php
}
?>
</table>
</div>
</div>
<!-- Book Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Book Modal content-->
<form id = "bookingform" action="login.php" method="post">
Username: <input type="username" id="username" placeholder="username"></br>
<button id="book">Book</button>
</form>
code for login.php
<?php
$user = $_POST['user'];
require "connectivity.php";
$date = date("Y-m-d");
$query = "SELECT member_forename FROM member WHERE name='$user'";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
}
elseif (mysqli_num_rows($result) == 0) {
echo "Username not recogised";
}
$sql = "INSERT INTO booking (booking_id, booking_date, customer_ID, bschedule_date, bschedule_class_id) VALUES ('15', '$date', '3', '2017-12-32')";
if(mysqli_query($con, $sql)) {
echo "booking made";
}
?>
login.js
$(document).ready(function(){
$("#login_btn").click(function(){
var user = $("#username").val();
var data = "user=" + user;
$.ajax({
method: "post",
url: "login.php?",
data: data,
success: function(data){
$("#login_error").html(data);
}
});
});