Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Classes.php INITIAL TABLE OF CLASS CHOICES:
- -------------------------------------------------------------------------------------------
- while ($row = mysqli_fetch_array($data)) {
- $new_date = $row['new_date'];
- $new_time = $row['new_time'];
- $venue = $row['venue'];
- echo '<tr><td>' . $new_date . '</td>';
- echo '<td>' . $new_time . '</td>';
- echo '<td>' . $venue . '</td>';
- echo '<td>' . $row['free_spaces'] . '</td>';
- echo '<form action="makebooking.php" method="get">';
- echo '<td><input type="checkbox" name="sesh[]" value="' . $row['class_id'] . '">';
- echo '<input type="hidden" name="date[]" value="' . $new_date . '" />';
- echo '<input type="hidden" name="time[]" value="' . $new_time . '" />';
- echo '<input type="hidden" name="venue[]" value="' . $venue . '" /></td></tr>';
- }
- echo'</table>';
- // Make booking button
- echo '<input type="submit" class="btn btn-large btn-primary pull-right" value="Book classes">';
- echo '</form>';
- -------------------------------------------------------------------------------------------
- //Makebooking.php $_GET AND $_POST TO REFLECT CHOICES AND ALLOW USER TO CONFIRM BEFORE UPDATING DB WITH BOOKING
- -------------------------------------------------------------------------------------------
- <?php
- //Start the session
- require_once('startsession.php');
- require_once('connectvars.php');
- //---------------------------------------------------------------------------------
- // Connect to the database
- $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
- //---------------------------------------------------------------------------------
- //Get user's ID from the users DB and set as $username
- $who = "SELECT first_name, last_name, user_id FROM users WHERE email = '" . $_SESSION['email'] . "'";
- $name = mysqli_query($dbc, $who);
- $row = mysqli_fetch_array($name);
- $username = $row['first_name'] . ' ' . $row['last_name'];
- //If GET is set, grab the data and store it in variables
- if (isset($_GET['sesh'])) {
- foreach ($_GET['sesh'] as $sesh) {
- $class_id = $_GET['sesh'];
- $date = $_GET['date'];
- $time = $_GET['time'];
- $venue = $_GET['venue'];
- }
- //---------------------------------------------------------------------------------
- //If POST info if all set:
- } else if (isset($_POST['date']) && isset($_POST['time']) && isset($_POST['venue']) && isset($_POST['username']) && isset($_POST['class_id'])) {
- foreach ($_POST['class_id'] as $classes) {
- $class_id = (int)$classes;
- $user_id = $_SESSION['user_id'];
- }
- } else {
- echo'<p>Oops, something went wrong. Please <a href="classes.php">go back</a> and try again.</p>';
- }
- //---------------------------------------------------------------------------------
- //If the confirm button has been hit:
- if (isset($_POST['submit'])) {
- //Create the foreach loop
- foreach ($_POST['class_id'] as $classes) {
- $class_id = (int)$classes;
- //UPDATE the bookings table;
- $query = "INSERT INTO bookings (user_id, booking_name, class_id, time_stamp) VALUES ('$user_id', '$username', '$class_id', NOW())";
- mysqli_query($dbc, $query);
- }
- mysqli_close($dbc);
- // REDIRECT
- $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/booking-confirmed.php';
- header('Location: ' . $home_url);
- }
- else {
- //Insert the page header
- $page_title='Make a booking';
- $description='Booking your Northallerton Zumba classes.';
- require_once('header.php');
- //html to set up the page layout
- ?>
- <body>
- <?php
- //Insert the navigation bar
- require_once('navbar.php');
- //---------------------------------------------------------------------------------
- //table header
- echo '<table class="table table-bordered table-hover">';
- echo '<thead><tr><th>Date</th><th>Time</th><th>Venue</th><th>Who\'s going?</th><th>Add someone</th></tr></thead>';
- //create the form
- echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
- //Get the class IDs from the GET to use in the POST
- foreach ($_GET['sesh'] as $class_id) {
- $sql = "SELECT class_id, DATE_FORMAT(date, '%a, %d %b') AS new_date, DATE_FORMAT(time, '%H:%i') AS new_time, venue FROM classes WHERE class_id = '$class_id'";
- $data = mysqli_query($dbc, $sql);
- //---------------------------------------------------------------------------------
- //get table data
- while ($row = mysqli_fetch_array($data)) {
- $date = $row["new_date"];
- $time = $row["new_time"];
- $venue = $row["venue"];
- $class_id = $row["class_id"];
- }
- //---------------------------------------------------------------------------------
- //Show a table of the selected classes
- echo '<td>' . $date . '</td>';
- echo '<td>' . $time . '</td>';
- echo '<td>' . $venue . '</td>';
- echo '<td>' . $username . '</td>';
- echo '<td><button class="btn btn-mini" type="button"><i class="icon-user"></i><i class="icon-plus"</i></button></td></tr>';
- echo '<input type="hidden" name="date[]" value="' . $date . '" />';
- echo '<input type="hidden" name="time[]" value="' . $time . '" />';
- echo '<input type="hidden" name="venue[]" value="' . $venue. '" />';
- echo '<input type="hidden" name="username[]" value="' . $username . '" />';
- echo '<input type="hidden" name="class_id[]" value="' . $class_id . '" />';
- }
- echo'</table>';
- //Go Back button
- echo '<a class="btn btn-link pull-left" href="classes.php"><i class="icon-arrow-left"></i> Go back</a>';
- // Make booking button
- echo '<input type="submit" name="submit" class="btn btn-large btn-primary pull-right" value="Confirm">';
- echo '</form>';
- }
- //}
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement