Advertisement
Guest User

Smegs pls2

a guest
Mar 1st, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3.  
  4. <body>
  5. <?php
  6.  
  7.  
  8.  
  9. $host = "sis-teach-01.sis.pitt.edu";
  10. $user = "bmw77";
  11. $password = "4021930";
  12. $dbname = "bmw77";
  13.  
  14. $connect = mysqli_connect($host, $user, $password, $dbname);
  15.  
  16.  
  17. // define variables and set to empty values
  18. $fnameErr = $lnameErr = $addressErr = $cityErr = $zipErr = $phoneErr = $quantityErr = $deliveryErr = "";
  19. $fname = $lname = $address = $city = $zip = $phone = $quantity = $delivery = "";
  20.  
  21.  
  22. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  23. if (empty($_POST["fname"])) {
  24. $fnameErr = "First Name is required";
  25. }
  26.  
  27. else {
  28. $fname = ($_POST["fname"]);
  29. // check if name only contains letters and apostrophes
  30. if (!preg_match("/^[a-zA-Z\' ]/",$fname)) {
  31. $fnameErr = "Only letters and white space allowed";
  32. }
  33. }
  34.  
  35.  
  36. if (empty($_POST["lname"])) {
  37. $lnameErr = "Last Name is required";
  38. }
  39.  
  40. else {
  41. $lname = ($_POST["lname"]);
  42. // check if name only contains letters and apostrophes
  43. if (!preg_match("/^[a-zA-Z\' ]/",$lname)) {
  44. $lnameErr = "Only letters and white space allowed";
  45. }
  46. }
  47.  
  48. if (empty($_POST["address"])) { //address checking that something was given
  49. $addressErr = "Address is required";
  50. }
  51. else {
  52. $address = ($_POST["address"]);
  53. }
  54.  
  55. if (empty($_POST["city"])) { //address checking that something was given
  56. $cityErr = "City is required";
  57. }
  58. else {
  59. $city = ($_POST["city"]);
  60. }
  61.  
  62. if (empty($_POST["phone"])) { // phone number checking for numbers and 10 digits
  63. $phoneErr = "Phone Number is required";
  64. }
  65. else {
  66. $phone = ($_POST["phone"]);
  67. if (preg_match("/\D/",$phone)) {
  68. $phoneErr = "Invalid Phone Number";
  69. }
  70. if(strlen($phone) !=10){
  71. $phoneErr = "Please enter a 10 digit Phone Number"; // I know the homework said 9 digits but phone numbers are usually 10 so I made it 10
  72. }
  73. }
  74.  
  75. if (empty($_POST["zip"])) { //zip checking for a zip and that it is valid
  76. $zipErr = "Zip Code is required";
  77. }
  78. else {
  79. $zip = ($_POST["zip"]);
  80. if (preg_match("/\D/",$zip)) {
  81. $zipErr = "Invalid Zip Code";
  82. }
  83. if (strlen($zip) != 5){
  84. $zipErr = "Zip Code should be 5 Characters" . $zip;
  85. }
  86.  
  87. }
  88.  
  89. if (empty($_POST["quantity"])) { // phone number checking for numbers and 10 digits
  90. $quantityErr = "Quantity is required";
  91. }
  92. else {
  93. $quantity = ($_POST["quantity"]);
  94. if (preg_match("/\D/",$quantity)) {
  95. $quantityErr = "Quantity must be a number";
  96. }
  97.  
  98. }
  99.  
  100. if (empty($_POST["delivery"])) { // type to check for a selection and keep it where it was
  101. $typeErr = "Delivery is required";
  102. }
  103. else {
  104. $delivery = ($_POST["delivery"]);
  105. }
  106. }
  107. $quantityInt = (int)$quantity;
  108. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  109. $result = mysqli_query($connect, "INSERT INTO assignment6(firstName, lastName, address, city, zip, quantity, phoneNum, deliveryMethod)
  110. VALUES('$fname', '$lname', '$address', '$city', '$zip', '$quantityInt', '$phone', '$delivery');");
  111. if (!$result) {
  112. echo 'Could not run query: ' . mysqli_error();
  113. exit;
  114. }
  115. }
  116.  
  117. $connect->close();
  118. ?>
  119.  
  120. <h2>NCAA Regulation Football</h2>
  121. <p> Our NCAA Regulation Footballs fit the NCAA rule for size. </p>
  122. <img src="football.jpg">
  123. <p><span class="error"></span></p>
  124. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  125.  
  126. First Name: <input type="text" name="fname" value="<?php echo $fname;?>"> <!-- text box for first name returns invalid if bad characters given or nothing is given !-->
  127. <span class="error">* <?php echo $fnameErr;?></span>
  128. <br><br>
  129.  
  130. Last Name: <input type="text" name="lname" value="<?php echo $lname;?>"> <!-- text box for last name returns invalid if bad characters given or nothing is given !-->
  131. <span class="error">* <?php echo $lnameErr;?></span>
  132. <br><br>
  133.  
  134. Address: <input type="text" name="address" value="<?php echo $address;?>"> <!-- text box for address only returns invalid if nothing is given !-->
  135. <span class="error">* <?php echo $addressErr;?></span>
  136. <br><br>
  137.  
  138. City: <input type="text" name="city" value="<?php echo $city;?>"> <!-- text box for city only returns invalid if nothing is given !-->
  139. <span class="error">* <?php echo $cityErr;?></span>
  140. <br><br>
  141.  
  142. Zip Code: <input type="text" name="zip" value="<?php echo $zip;?>"> <!-- text box for zip code that requires numbers !-->
  143. <span class="error">* <?php echo $zipErr;?></span>
  144. <br><br>
  145.  
  146. Phone Number: <input type="text" name="phone" value="<?php echo $phone;?>"> <!-- text box for phone number it forces a 10 digit number because thats what most phone numbers are !-->
  147. <span class="error">*<?php echo $phoneErr;?></span>
  148. <br><br>
  149.  
  150. Quantity: <input type="text" name="quantity" value="<?php echo $quantity;?>"> <!-- textbox for quantity and checks that there is a value !-->
  151. <span class="error">*<?php echo $quantityErr;?></span>
  152. <br><br>
  153.  
  154. Delivery Method <!-- Radio Buttons for final question !-->
  155. <input type="radio" name="delivery" <?php if (isset($delivery) && $delivery=="Standard") echo "checked";?> value="Standard">Standard
  156. <input type="radio" name="delivery" <?php if (isset($delivery) && $delivery=="Two-Day") echo "checked";?> value="Two-Day">Two-Day
  157. <input type="radio" name="delivery" <?php if (isset($delivery) && $delivery=="Next-Day") echo "checked";?> value="Next-Day">Next-Day
  158. <span class="error">* <?php echo $deliveryErr;?></span>
  159. <br><br>
  160. <input type="submit" name="submit" value="Submit">
  161. <br><br>
  162.  
  163. <?php
  164. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  165. if(($fnameErr == "") && ($lnameErr == "") && ($addressErr == "") && ($zipErr == "") && ($phoneErr == "") && ($quantityErr == "") && ($deliveryErr == "") && ($cityErr == "")){ //If statement telling that all information is valid
  166. echo "Order Submitted Successfully";
  167. }
  168. }
  169.  
  170. ?>
  171.  
  172. </form>
  173. </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement