Advertisement
Guest User

Untitled

a guest
May 20th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ob_start();
  4. include "include/dbconnect.php";
  5. ?>
  6. <html>
  7. <head>
  8. <title>Beginning PHP5, Apache and MySQL</title>
  9. </head>
  10. <body>
  11. <?php
  12. if (isset($_POST['submit']) && $_POST['submit'] == "Register") {
  13. if ($_POST['username'] != "" &&
  14. $_POST['password'] != "" &&
  15. $_POST['first_name'] != "" &&
  16. $_POST['last_name'] != "" &&
  17. $_POST['email'] != "") {
  18.  
  19. $query = "SELECT username FROM rc_accounts " .
  20. "WHERE username = '" . $_POST['username'] . "';";
  21. $result = mysql_query($query)
  22. or die(mysql_error());
  23.  
  24. if (mysql_num_rows($result) != 0) {
  25. ?>
  26. <p>
  27. <font color="#FF0000"><b>The Username,
  28. <?php echo $_POST['username']; ?>, is already in use, please choose
  29. another!</b></font>
  30. <form action="register.php" method="post">
  31. Username: <input type="text" name="username"><br>
  32. Password: <input type="password" name="password"
  33. value="<?php echo $_POST['password']; ?>"><br>
  34. Email: <input type="text" name="email"
  35. alue="<?php echo $_POST['email']; ?>"><br>
  36. First Name: <input type="text" name="first_name"
  37. value="<?php echo $_POST['first_name']; ?>"><br>
  38. Last Name: <input type="text" name="last_name"
  39. value="<?php echo $_POST['last_name']; ?>"><br>
  40. City: <input type="text" name="city"
  41. value="<?php echo $_POST['city']; ?>"><br>
  42. State: <input type="text" name="state"
  43. value="<?php echo $_POST['state']; ?>"><br><br>
  44. <input type="submit" name="submit" value="Register"> &nbsp;
  45. <input type="reset" value="Clear">
  46. </form>
  47. </p>
  48. <?php
  49. } else {
  50. $query = "INSERT INTO rc_accounts (username, password, email, " .
  51. "first_name, last_name, city, state, hobbies) " .
  52. "VALUES ('" . $_POST['username'] . "', " .
  53. "(PASSWORD('" . $_POST['password'] . "')), '" .
  54. $_POST['email'] . "', '" . $_POST['first_name'] .
  55. "', '" . $_POST['last_name'] . "', '" . $_POST['city'] .
  56. "', '" . $_POST['state'] . "', '" .
  57. implode(", ", $_POST['hobbies']) . "');";
  58. $result = mysql_query($query)
  59. or die(mysql_error());
  60. $_SESSION['user_logged'] = $_POST['username'];
  61. $_SESSION['user_password'] = $_POST['password'];
  62. ?>
  63. <p>
  64. Thank you, <?php echo $_POST['first_name'] . " " .
  65. $_POST['last_name']; ?> for registering!<br>
  66. <?php
  67. header("Refresh: 5; URL=index.php");
  68. echo "Your registration is complete! " .
  69. "You are being sent to the page you requested!<br>";
  70. echo "(If your browser doesn't support this, " .
  71. "<a href=\"index.php\">click here</a>)";
  72. die();
  73. }
  74. } else {
  75. ?>
  76. <p>
  77. <font color="#FF0000"><b>The Username, Password, Email, First Name,
  78. and Last Name fields are required!</b></font>
  79. <form action="register.php" method="post">
  80. Username: <input type="text" name="username"
  81. value="<?php echo $_POST['username']; ?>"><br>
  82. Password: <input type="password" name="password"
  83. value="<?php echo $_POST['password']; ?>"><br>
  84. Email: <input type="text" name="email"
  85. value="<?php echo $_POST['email']; ?>"><br>
  86. First Name: <input type="text" name="first_name"
  87. value="<?php echo $_POST['first_name']; ?>"><br>
  88. Last Name: <input type="text" name="last_name"
  89. value="<?php echo $_POST['last_name']; ?>"><br>
  90. City: <input type="text" name="city"
  91. value="<?php echo $_POST['city']; ?>"><br>
  92. State: <input type="text" name="state"
  93. value="<?php echo $_POST['state']; ?>"><br><br>
  94. <input type="submit" name="submit" value="Register"> &nbsp;
  95. <input type="reset" value="Clear">
  96. </form>
  97. </p>
  98. <?php
  99. }
  100. } else {
  101. ?>
  102. <p>
  103. Welcome to the registration page!<br>
  104. The Username, Password, Email, First Name, and Last Name fields
  105. are required!
  106. <form action="register.php" method="post">
  107. Username: <input type="text" name="username"><br>
  108. Password: <input type="password" name="password"><br>
  109. Email: <input type="text" name="email"><br>
  110. First Name: <input type="text" name="first_name"><br>
  111. Last Name: <input type="text" name="last_name"><br>
  112. City: <input type="text" name="city"><br>
  113. State: <input type="text" name="state"><br><br>
  114. <input type="submit" name="submit" value="Register"> &nbsp;
  115. <input type="reset" value="Clear">
  116. </form>
  117. </p>
  118. <?php
  119. }
  120. ?>
  121. </body>
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement