Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. $servername = "localhost";
  2. $username = "root"; $password = "";
  3. $dbname = "users_db";
  4. $conn = new mysqli($servername, $username, $password, $dbname);
  5.  
  6. if (mysqli_connect_errno())
  7. { echo "MySQLi Connection was not established: " . mysqli_connect_error();
  8. }
  9.  
  10. ?>
  11. <html>
  12. <head>
  13. <title>Beginning PHP5,APACHE AND MySQLi</title>
  14. </head>
  15. <body>
  16. <?php
  17. if (isset($_POST['submit']) && $_POST['submit'] == "Register") {
  18. if ($_POST['username'] != "" &&
  19. $_POST['password'] != "" &&
  20. $_POST['first_name'] != "" &&
  21. $_POST['last_name'] != "" &&
  22. $_POST['email'] != "") {
  23. $query = "SELECT username FROM user_info " .
  24. "WHERE username = '" . $_POST['username'] . "';";
  25.  
  26. $result = mysqli_query($conn, $query)
  27. or die(mysqli_error()); **This is line 31**
  28. if (mysqli_num_rows($result) != 0){
  29.  
  30.  
  31. ?>
  32.  
  33. <p>
  34. <p>
  35. <font color="#FF0000"><b>The Username,
  36. <?php echo $_POST['username']; ?>, is already in use, please choose
  37. another!</b></font>
  38. <form action="registration.php" method="post">
  39. Username: <input type="text" name="username"><br>
  40. Password: <input type="password" name="password"
  41. value="<?php echo $_POST['password']; ?>"><br>
  42. Email: <input type="text" name="email"
  43. value="<?php echo $_POST['email']; ?>"><br>
  44. First Name: <input type="text" name="first_name"
  45. value="<?php echo $_POST['first_name']; ?>"><br>
  46. Last Name: <input type="text" name="last_name"
  47. value="<?php echo $_POST['last_name']; ?>"><br>
  48. City: <input type="text" name="city"
  49. value="<?php echo $_POST['city']; ?>"><br>
  50. County: <input type="text" name="state"
  51. value="<?php echo $_POST['county']; ?>"><br>
  52. Car Models: choose at least one)<br>
  53. <select name="car_type" size="" multiple>
  54. <option value="Volkswagen"<?php
  55. if(in_array("Volkswagen", $_POST['car_type'])){
  56. echo "selected";
  57. }?>>BMW</option>
  58. <option value="BMW"<?php
  59. if(in_array("BMW", $_POST['car_type'])){
  60. echo "selected";
  61. }?>>Ford</option>
  62. <option value="Ford"<?php
  63. if(in_array("Ford", $_POST['car_type'])){
  64. echo "selected";
  65. }?>>Fiat</option>
  66. <option value="Fiat"<?php
  67. if(in_array("Fiat", $_POST['car_type'])){
  68. echo "selected";
  69. }?>>Toyota</option>
  70. <option value="Toyota"<?php
  71. if(in_array("Toyota", $_POST['car_type'])){
  72. echo "selected";
  73. }?>>Other Than Listed</option>
  74. <option value="Other Than Listed"<?php
  75. if (in_array("Other Than Listed", $_POST['hobbies'])) {
  76. echo " selected";
  77. } ?>>Other Than Listed</option>
  78. </select><br><br>
  79. <input type="submit" name="submit" value="Register"> &nbsp;
  80. <input type="reset" value="Clear">
  81. </form>
  82. </p>
  83. <?php
  84. } else {
  85. $query = "INSERT INTO user_info (username, password, email, " .
  86. "first_name, last_name, city, county, car_type) " .
  87. "VALUES ('" . $_POST['username'] . "', " .
  88. "(PASSWORD('" . $_POST['password'] . "')), '" .
  89. $_POST['email'] . "', '" . $_POST['first_name'] .
  90. "', '" . $_POST['last_name'] . "', '" . $_POST['city'] .
  91. "', '" . $_POST['county'] . "', '" .
  92. implode(", ", $_POST['car_type']) . "');";
  93. $result = mysqli_query($conn,$query) or die(mysqli_error());
  94. $_SESSION['user_logged'] = $_POST['username'];
  95. $_SESSION['user_password'] = $_POST['password'];
  96. ?>
  97. <p>
  98. Thank you, <?php echo $_POST['first_name'] . " " .
  99. $_POST['last_name']; ?> for registering!<br>
  100. <?php
  101. header("Refresh: 5; URL=index.php");
  102. echo "Your registration is complete! " .
  103. "You are being sent to the page you requested!<br>";
  104. echo "(If your browser doesn’t support this, ".
  105. "<a href="index.php">click here</a>)";
  106. die();
  107. }
  108. } else {
  109. ?>
  110. <p>
  111. <font color="#FF0000"><b>The Username, Password, Email, First Name,
  112. and Last Name fields are required!</b></font>
  113. <form action="registration.php" method="post">
  114. Username: <input type="text" name="username"
  115. value="<?php echo $_POST['username']; ?>"><br>
  116. Password: <input type="password" name="password"
  117. value="<?php echo $_POST['password']; ?>"><br>
  118. Email: <input type="text" name="email"
  119. value="<?php echo $_POST['email']; ?>"><br>
  120. First Name: <input type="text" name="first_name"
  121. value="<?php echo $_POST['first_name']; ?>"><br>
  122. Last Name: <input type="text" name="last_name"
  123. value="<?php echo $_POST['last_name']; ?>"><br>
  124. City: <input type="text" name="city"
  125. value="<?php echo $_POST['city']; ?>"><br>
  126. State: <input type="text" name="state"
  127. value="<?php echo $_POST['state']; ?>"><br>
  128. Car models: (choose at least one)<br>
  129. <select name="car_type[]" size="10" multiple>
  130. <option value="Volkswagen"<?php
  131. if (in_array("Volkswagen", $_POST['car_type'])) {
  132. echo " selected";
  133. } ?>>Volkswagen</option>
  134. <option value="BMW"<?php
  135. if (in_array("BMW", $_POST["car_type"])) {
  136. echo " selected";
  137. } ?>>BMW</option>
  138. <option value="Ford"<?php
  139. if (in_array("Ford", $_POST["car_type"])) {
  140. echo " selected";
  141. } ?>>Ford</option>
  142. <option value="Toyota"<?php
  143. if (in_array("Toyota", $_POST["car_type"])) {
  144. echo " selected";
  145. } ?>>Toyota</option>
  146. <option value="Fiat"<?php
  147. if (in_array("Fiat", $_POST["car_type"])) {
  148. echo " selected";
  149. } ?>>"Fiat</option>
  150. <option value=">Other Than Listed"<?php
  151. if (in_array(">Other Than Listed", $_POST["car_type"])) {
  152. echo " selected";
  153. } ?>>Other Than Listed</option>
  154. </select><br><br>
  155. <input type="submit" name="submit" value="Register"> &nbsp;
  156. <input type="reset" value="Clear">
  157. </form>
  158. </p>
  159. <?php
  160. }
  161. } else {
  162. ?>
  163. <p>
  164. Welcome to the registration page!<br>
  165. The Username, Password, Email, First Name, and Last Name fields
  166. are required!
  167. <form action="registration.php" method="post">
  168. Username: <input type="text" name="username"><br>
  169. Password: <input type="password" name="password"><br>
  170. Email: <input type="text" name="email"><br>
  171. First Name: <input type="text" name="first_name"><br>
  172. Last Name: <input type="text" name="last_name"><br>
  173. City: <input type="text" name="city"><br>
  174. County: <input type="text" name="county"><br>
  175. Car models: (choose at least one)<br>
  176. <select name="car_type[]" size=”10” multiple>
  177. <option value="Volkswagen">Golfing</option>
  178. <option value="BMW">BMW</option>
  179. <option value="Ford">Ford</option>
  180. <option value="Toyota">Toyota</option>
  181. <option value="Fiat">Fiat</option>
  182. <option value="Other Than Listed">Other Than Listed</option>
  183.  
  184. </select><br><br>
  185. <input type="submit" name="submit" value="Register"> &nbsp;
  186. <input type="reset" value="Clear">
  187. </form>
  188. </p>
  189. <?php
  190. }
  191. ?>
  192. </body>
  193. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement