Guest User

Untitled

a guest
Oct 28th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. // variable declaration
  5. $username = "";
  6. $email = "";
  7. $errors = array();
  8. $_SESSION['success'] = "";
  9.  
  10.  
  11. $db = mysqli_connect('localhost', 'root', '', 'registration');
  12.  
  13. // SIGNUP CUSTOMER
  14. if (isset($_POST['reg_user'])) {
  15.  
  16. $username = mysqli_real_escape_string($db, $_POST['username']);
  17. $email = mysqli_real_escape_string($db, $_POST['email']);
  18. $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
  19. $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
  20. $telephone = mysqli_real_escape_string($db,$_POST['telephone']);
  21. $country = mysqli_real_escape_string($db,$_POST['country']);
  22. $state= mysqli_real_escape_string($db,$_POST['state']);
  23.  
  24.  
  25. if (empty($username)) { array_push($errors, "Username is required"); }
  26. if (empty($email)) { array_push($errors, "Email is required"); }
  27. if (empty($password_1)) { array_push($errors, "Password is required"); }
  28. if (empty($telephone)) { array_push($errors, "Telephone no. is required"); }
  29. if (empty($country)) { array_push($errors, "country is required"); }
  30. if (empty($state)) { array_push($errors, "state is required"); }
  31.  
  32. if ($password_1 != $password_2) {
  33. array_push($errors, "The two passwords do not match");
  34. }
  35.  
  36.  
  37. if (count($errors) == 0) {
  38. $password = md5($password_1);
  39. $query = "INSERT INTO users (username, email, password, telephone,country,state)
  40. VALUES('$username', '$email', '$password','$telephone','$country','$state')";
  41. mysqli_query($db, $query);
  42.  
  43. $_SESSION['username'] = $username;
  44. $_SESSION['success'] = "You are now logged in";
  45. header('location: index1.php');
  46. }
  47.  
  48. }
  49. // ...
  50.  
  51. // SIGNIN CUSTOMER
  52. if (isset($_POST['login_user'])) {
  53. $username = mysqli_real_escape_string($db, $_POST['username']);
  54. $password = mysqli_real_escape_string($db, $_POST['password']);
  55.  
  56. if (empty($username)) {
  57. array_push($errors, "Username is required");
  58. }
  59. if (empty($password)) {
  60. array_push($errors, "Password is required");
  61. }
  62.  
  63. if (count($errors) == 0) {
  64. $password = md5($password);
  65. $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
  66. $results = mysqli_query($db, $query);
  67.  
  68. if (mysqli_num_rows($results) == 1) {
  69. $_SESSION['username'] = $username;
  70. $_SESSION['success'] = "You are now logged in";
  71. header('location: index1.php');
  72. }else {
  73. array_push($errors, "Wrong username/password combination");
  74. }
  75. }
  76. }
  77. //SIGN UP DEALER
  78. if (isset($_POST['reg_dealer'])) {
  79.  
  80. $username = mysqli_real_escape_string($db, $_POST['username']);
  81. $email = mysqli_real_escape_string($db, $_POST['email']);
  82. $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
  83. $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
  84. $account = mysqli_real_escape_string($db, $_POST['account']);
  85. $IFSC = mysqli_real_escape_string($db,$_POST['IFSC']);
  86. $target = mysqli_real_escape_string($db,$_POST['target']);
  87. $sales= mysqli_real_escape_string($db,$_POST['sales']);
  88. $date= mysqli_real_escape_string($db,$_POST['date']);
  89. $address= mysqli_real_escape_string($db,$_POST['address']);
  90. $telephone = mysqli_real_escape_string($db,$_POST['telephone']);
  91. $country = mysqli_real_escape_string($db,$_POST['country']);
  92. $state= mysqli_real_escape_string($db,$_POST['state']);
  93.  
  94.  
  95.  
  96. if (empty($username)) { array_push($errors, "Username is required"); }
  97. if (empty($email)) { array_push($errors, "Email is required"); }
  98. if (empty($password_1)) { array_push($errors, "Password is required"); }
  99. if (empty($telephone)) { array_push($errors, "Telephone no. is required"); }
  100. if (empty($country)) { array_push($errors, "country is required"); }
  101. if (empty($state)) { array_push($errors, "state is required"); }
  102. if (empty($account)) { array_push($errors, "account is required"); }
  103.  
  104. if (empty($IFSC)) { array_push($errors, "IFSC is required"); }
  105.  
  106. if (empty($sales)) { array_push($errors, "sales is required"); }
  107.  
  108. if (empty($date)) { array_push($errors, "date is required"); }
  109.  
  110. if (empty($target)) { array_push($errors, "target is required"); }
  111.  
  112. if (empty($address)) { array_push($errors, "address is required"); }
  113.  
  114.  
  115. if ($password_1 != $password_2) {
  116. array_push($errors, "The two passwords do not match");
  117. }
  118.  
  119.  
  120. if (count($errors) == 0) {
  121. $password = md5($password_1);
  122. $query = "INSERT INTO dealers (username, email, password, account,IFSC,target,sales, date,address,telephone,country,state)
  123. VALUES('$username', '$email', '$password','$account','$IFSC','$target','$sales','$date','$address',$telephone','$country','$state')";
  124. mysqli_query($db, $query);
  125.  
  126. $_SESSION['username'] = $username;
  127. $_SESSION['success'] = "You are now logged in";
  128. header('location: index1.php');
  129. }
  130.  
  131. }
  132. //SIGNIN DEALER
  133. if (isset($_POST['login_dealer'])) {
  134. $username = mysqli_real_escape_string($db, $_POST['username']);
  135. $password = mysqli_real_escape_string($db, $_POST['password']);
  136.  
  137. if (empty($username)) {
  138. array_push($errors, "Username is required");
  139. }
  140. if (empty($password)) {
  141. array_push($errors, "Password is required");
  142. }
  143.  
  144. if (count($errors) == 0) {
  145. $password = md5($password);
  146. $query = "SELECT * FROM dealers WHERE username='$username' AND password='$password'";
  147. $results = mysqli_query($db, $query);
  148.  
  149. if (mysqli_num_rows($results) == 1) {
  150. $_SESSION['username'] = $username;
  151. $_SESSION['success'] = "You are now logged in";
  152. header('location: index1.php');
  153. }else {
  154. array_push($errors, "Wrong username/password combination");
  155. }
  156. }
  157. }
  158.  
  159.  
  160. ?>
Add Comment
Please, Sign In to add comment