Guest User

Peanut Butter

a guest
Mar 9th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2. // Checks if the submit button was clicked
  3. if ($_POST["submit"] == "Submit") {
  4. // Checks if there were no errors in the form
  5. if ($error != true) {
  6. // Sets the variables for connection details
  7. $servername = "localhost";
  8. $username = "wessamallami";
  9. $password = "circle8";
  10. $dbname = "wallami";
  11. // Connects to the database
  12. $conn = mysqli_connect($servername, $username, $password, $dbname);
  13. // Checks if the connection was unsuccessful and if it was, it displays an error
  14. if (!$conn) {
  15. die("Connection failed: " . mysqli_connect_error());
  16. } else {
  17. echo "Connection successful.";
  18. }
  19. // Creates the SQL code to check if the game is reserved already
  20. $checkSQL = "SELECT Game_ID
  21. FROM Reservations
  22. WHERE (Start_Date between '".$startDate."' and '".$endDate."' or End_Date between '".$startDate."' and '".$endDate."')
  23. AND Game_ID = '".$gameID."'";
  24. // Runs the SQL query
  25. $result = mysqli_query($conn, $checkSQL);
  26. // Checks if the query returned a result
  27. if (mysqli_num_rows($result) > 0) {
  28. // If it did, notfiy the user the game is reserved and do nothing more
  29. echo "<br><br>Sorry, this game is already reserved during these days. Please try another date.";
  30. } else {
  31. //If it did not return anything, then create the SQL query to insert the data into the database
  32. $sql = "INSERT INTO Reservations (Customer_Name, Game_ID, Start_Date, End_Date, Number_Of_Days_Reserved)
  33. VALUES ('".$name."', '".$gameID."', '".$startDate."', '".$endDate."', '".$NoOfDays."')";
  34. // Check if the query was run successfully
  35. if ($conn->query($sql)) {
  36. // If it was, tell the user the reservation was saved.
  37. echo "<br><br> Reservation Saved.";
  38. } else {
  39. // If not, display the error to the user.
  40. echo "Error: " . $sql . "<br>" . $conn->error;
  41. }
  42. // Close the connection to prevent any further errors.
  43. $conn->close();
  44. }
  45. }
  46. }
  47. ?>
Add Comment
Please, Sign In to add comment