Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Games Library Reservations Page</title>
  6. <link href="styles.css" rel="stylesheet" type="text/css">
  7. </head>
  8.  
  9. <body>
  10. <div id='main'>
  11. <div id='titleImage'><img title='Home' src='images/GLLogo.png' width='700' height='190' alt='Games Library Title' /></div>
  12. <div id='menu-wrapper'>
  13. <div id='menu'>
  14. <ul>
  15.  
  16. <li><a href='index.php'>Home</a></li>
  17. <li class='current_page_item'><a href='#'>Reservations</a></li>
  18. </ul>
  19. </div>
  20. </div>
  21.  
  22. <div>
  23. <h1>Reservations</h1>
  24. <?php
  25. $count = 0;
  26. $file = fopen('games.csv', 'r');
  27. while(($games[] = fgetcsv($file)) !== FALSE){
  28. $count = $count + 1;
  29. }
  30.  
  31. //saves into an array
  32. fclose($file);
  33.  
  34. $name = $gameID = $start = $reserve = "";
  35. $nameErr = $gameIDErr = $startrErr = $reserveErr ="";
  36.  
  37. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  38. if(empty($_POST["name"])) {
  39. $nameErr = "Name is required";
  40. } else {
  41. $name = $_POST["name"];
  42. }
  43. if(empty($_POST["gameID"])) {
  44. $gameIDErr = "gameID is required";
  45. } else {
  46. $gameID = $_POST["gameID"];
  47. }
  48. if(empty($_POST["start"])) {
  49. $startErr = "start is required";
  50. } else {
  51. $start = $_POST["start"];
  52. }
  53. if(empty($_POST["reserve"])) {
  54. $reserveErr = "reserve is required";
  55. }else{
  56. $reserve = $_POST["reserve"];
  57. }
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. $match = "no" ;
  65. $number_of_records = $count - 1 ;
  66. for ($i = 0;$i<$number_of_records;$i++) {
  67. if ($gameID == $games[$i][0]) {
  68. $match = "yes";
  69. $gamename = $games[$i][2];
  70. $price = $games[$i][4];
  71. $validgameID = $games[$i][0];
  72.  
  73.  
  74. }
  75. }
  76. if($match == "no"){
  77. $gameIDErr = "Game ID does not exist";
  78. }
  79.  
  80.  
  81. $servername = "localhost";
  82. $username = "vaudibert1";
  83. $password = "ebscs";
  84. $dbname = "vaudibert";
  85.  
  86. $conn = new MySQLi($servername, $username, $password, $dbname);
  87. if ($conn->connect_error) {
  88. die("connection failed: " . $conn->connect_error);
  89. }else{
  90. $enddate = date('Y-m-d', strtotime($reserve."+($days)days"));
  91.  
  92.  
  93. $sql = "INSERT INTO reservation (name, gameID, start, reserve, enddate)
  94. VALUES('".$name."','".$gameID."','".$start."','".$reserve."','".$enddate."')";
  95.  
  96. if($conn->query($sql) === TRUE ) {
  97. echo "new record successfully created";
  98. } else {
  99. echo "Error: ". $sql . "<br>" .$conn->error;
  100. }
  101.  
  102. $conn->close();
  103.  
  104.  
  105.  
  106. ?>
  107. <style>
  108. .error {color: #FF0000;}
  109. </style>
  110.  
  111. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  112.  
  113. <p>Name:</p>
  114. <p>
  115. <input type="text" name="name">
  116. <span class="error">* <?php echo $nameErr;?></span>
  117. <br><br>
  118. gameID:</p>
  119. <p>
  120. <input type="text" name="gameID">
  121. <span class="error">* <?php echo $gameIDErr;?></span>
  122. <br><br>
  123. Start date of reservation: </p>
  124. <p>
  125. <input type="date" name="start">
  126. <span class="error">* <?php echo $startErr;?></span>
  127. <br>
  128. <p>Number of days for reservation:<br>
  129. <p>
  130. <input type="number" name="reserve" min="1" max="5">
  131. <span class="error">* <?php echo $reserveErr;?></span>
  132. <br><br>
  133. <input type="submit" name="submit" value="Submit">
  134. </p>
  135. <br><br>
  136. </p>
  137. </form>
  138.  
  139.  
  140.  
  141. <?php
  142.  
  143.  
  144.  
  145.  
  146. echo "<h2>Your Input:</h2>";
  147. echo $name;
  148. echo"<br>";
  149. echo $gameID;
  150. echo"<br>";
  151. echo $start;
  152. echo"<br>";
  153. echo $reserve;
  154. echo"<br>";
  155. echo $match;
  156. echo"<br>";
  157. echo "The game name is: ". $gamename;
  158. $totalprice = $price * $reserve;
  159. echo "<br>";
  160. echo "The price for ".$reserve." days is £".$totalprice.".";
  161.  
  162. }
  163. ?>
  164.  
  165.  
  166. </div>
  167.  
  168. </body>
  169. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement