Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //connect to mysql database
- $servername = "localhost";
- $username = "yneocleous";
- $password = "ebscs";
- $dbname = "yneocleous";
- if ($_POST["submit"] == "Submit") {
- // Checks if there were no errors in the form
- if ($error != true) {
- // Sets the variables for connection details
- $servername = "localhost";
- $username = "yneocleous";
- $password = "ebscs";
- $dbname = "yneocleous";
- // Connects to the database
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Checks if the connection was unsuccessful and if it was, it displays an error
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- } else {
- echo "Connection successful.";
- }
- // Creates the SQL code to check if the game is reserved already
- $checkSQL = "SELECT game_ID
- FROM Reservations
- WHERE (start_reservation between'".$start_reservation."' and '".$end_date."' OR end_date between'".$start_reservation."' and '".$end_date."')
- AND game_ID = '".$gameID."'";
- // Runs the SQL query
- $result = mysqli_query($conn, $checkSQL);
- // Checks if the query returned a result
- if (mysqli_num_rows($result) > 0) {
- // If it did, notfiy the user the game is reserved and do nothing more
- echo "<br><br>Sorry, this game is already reserved during these days. Please try another date.";
- } else {
- //If it did not return anything, then create the SQL query to insert the data into the database
- $sql = "INSERT INTO Reservations (first_name, last_name, game_ID, start_reservation, num_days, end_date)
- VALUES ('".$first_name."', '".$last_name."', '".$gameID."', '".$start_reservation."', '".$num_days."', '".$end_date."')";
- // Check if the query was run successfully
- if ($conn->query($sql)) {
- // If it was, tell the user the reservation was saved.
- echo "<br><br> Reservation Saved.";
- } else {
- // If not, display the error to the user.
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- // Close the connection to prevent any further errors.
- $conn->close();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement