Advertisement
Guest User

Untitled

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