Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. <?php
  2. $page_title = 'Register';
  3. include ('header.html');
  4.  
  5. if (isset($_POST['submitted'])) {
  6. $errors = array();
  7.  
  8. if (empty($_POST['first_name'])) {
  9. $errors[] = 'You forgot to enter your first name.';
  10.  
  11. } else {
  12. $fn = trim($_POST['first_name']);
  13. }
  14.  
  15. if (empty($_POST['last_name'])) {
  16. $errors[] = 'You forgot to enter your last name.';
  17.  
  18. } else {
  19. $ln = trim($_POST['last_name']);
  20. }
  21.  
  22. if (empty($_POST['email'])) {
  23. $errors[] = 'You forgot to enter your email address.';
  24.  
  25. } else {
  26. $e = trim($_POST['email']);
  27. }
  28.  
  29. if (empty($_POST['phone'])) {
  30. $errors[] = 'You forgot to enter your phone number.';
  31.  
  32. } else {
  33. $ph = trim($_POST['phone']);
  34. }
  35.  
  36. if (empty($_POST['address_line1'])) {
  37. $errors[] = 'You forgot to enter your billing address.';
  38.  
  39. } else {
  40. $ad1 = trim($_POST['address_line1']);
  41. }
  42.  
  43. if (empty($_POST['suburb'])) {
  44. $errors[] = 'You forgot to enter your City/Suburb.';
  45.  
  46. } else {
  47. $s = trim($_POST['suburb']);
  48. }
  49.  
  50. if (empty($_POST['postcode'])) {
  51. $errors[] = 'You forgot to enter your postcode.';
  52.  
  53. } else {
  54. $pc = trim($_POST['postcode']);
  55. }
  56.  
  57. if (empty($_POST['username'])) {
  58. $errors[] = 'You forgot to enter a username.';
  59.  
  60. } else {
  61. $un = trim($_POST['username']);
  62. }
  63.  
  64. if (!empty($_POST['pass1'])) {
  65. if ($_POST['pass1'] !=
  66. $_POST['pass2']) {
  67. $errors[] = 'Your password did not match the confirmed password.';
  68.  
  69. } else {
  70. $p = trim($_POST['pass1']);
  71. }
  72.  
  73. } else {
  74. $errors[] = 'You forgot to enter a password.';
  75. }
  76.  
  77. if (empty($errors)) {
  78.  
  79. require_once
  80. ('mysqli_connect.php');
  81. $q = "INSERT INTO users (first_name, last_name, email, phone, address_line1, suburb, postcode, username, pass, registration_date) VALUES ('$fn', '$ln', '$e', '$ph', '$ad1', '$s', '$pc', '$un', SHA1('$p'), NOW() )";
  82. $r = @mysqli_query ($dbc, $q);
  83.  
  84. if ($r) {
  85. echo '<h1>Thank you!</h1>
  86. <p>You are now registered.</p><p><br /></p>';
  87.  
  88. } else {
  89. echo '<h1>System Error</h1>
  90. <p class="error">You could not be registered due to a system error. We apologise for any inconvenience.</p>';
  91. echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
  92. }
  93.  
  94. mysqli_close($dbc);
  95. include ('footer.html');
  96. exit();
  97.  
  98. } else {
  99. echo '<h1>Error!</h1>
  100. <p class="error">The following error(s) occurred: <br />';
  101. foreach ($errors as $msg) {
  102. echo " - $msg<br />\n";
  103. }
  104. echo '</p><p>Please try again.</p><p><br /></p>';
  105. }
  106. }
  107.  
  108. ?>
  109.  
  110. <div id="maincontent">
  111. <fieldset><legend>
  112. <h2>Register:</h2>
  113. </legend>
  114.  
  115. <form action="register.php" method ="post">
  116. <p>First name: <br /><input type="text" name="first_name" size="60" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
  117. <p>Last name: <br /><input type="text" name="last_name" size="60" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
  118. <p>Email address: <br /><input type="text" name="email" size="60" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
  119. <p>Phone: <input type="text" name="phone" size="20" maxlength="20" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>" /></p>
  120. <p>Company name: <br /><input type="text" name="company_name" size="60" maxlength="100" value="<?php if (isset($_POST['company_name'])) echo $_POST['company_name']; ?>" /></p>
  121. <p>Billing address: <br /><input type="text" name="address_line1" size="60" maxlength="80" value="<?php if (isset($_POST['address_line1'])) echo $_POST['address_line1']; ?>" /></p>
  122. <p>Billing address (con't): <br /><input type="text" name="address_line2" size="60" maxlength="80" value="<?php if (isset($_POST['address_line2'])) echo $_POST['address_line2']; ?>" /></p>
  123. <p>City/Suburb: <br /><input type="text" name="suburb" size="60" maxlength="80" value="<?php if (isset($_POST['suburb'])) echo $_POST['suburb']; ?>" /></p>
  124. <p>State: <br /><input type="text" name="state" size="20" maxlength="3" value="<?php if (isset($_POST['state'])) echo $_POST['state']; ?>" /></p>
  125. <p>Postcode: <br /><input type="text" name="postcode" size="20" maxlength="10" value="<?php if (isset($_POST['postcode'])) echo $_POST['postcode']; ?>" /></p>
  126. <p>Username: <br /><input type="text" name="username" size="60" maxlength="80" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
  127. <p>Password: <br /><input type="password" name="pass1" size="60" maxlength="20" /></p>
  128. <p>Confirm Password: <br /><input type="password" name="pass2" size="60" maxlength="20" /></p>
  129. <p><input type="submit" name="submit" value="Register" /></p>
  130. <input type="hidden" name="submitted" value="TRUE" />
  131. </form>
  132. </fieldset>
  133.  
  134. </div>
  135.  
  136. <?php
  137. include ('footer.html');
  138. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement