Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Checks if the submit button was clicked
- 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 = "wessamallami";
- $password = "circle8";
- $dbname = "wallami";
- // 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_Date between '".$startDate."' and '".$endDate."' or End_Date between '".$startDate."' and '".$endDate."')
- 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 (Customer_Name, Game_ID, Start_Date, End_Date, Number_Of_Days_Reserved)
- VALUES ('".$name."', '".$gameID."', '".$startDate."', '".$endDate."', '".$NoOfDays."')";
- // 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();
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment