Advertisement
Guest User

Untitled

a guest
Nov 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. // REGISTER USER
  2. if (isset($_POST['reg_user'])) {
  3. // receive all input values from the form
  4. $username = mysqli_real_escape_string($db, $_POST['username']);
  5. $password = mysqli_real_escape_string($db, $_POST['password']);
  6. $city = mysqli_real_escape_string($db, $_POST['city']);
  7. $state = mysqli_real_escape_string($db, $_POST['state']);
  8. $country = mysqli_real_escape_string($db, $_POST['country']);
  9.  
  10.  
  11. if (empty($username)) { array_push($errors, "Username is required"); }
  12. if (empty($password)) { array_push($errors, "Password is required"); }
  13. if (empty($city)) { array_push($errors, "City is required"); }
  14. if (empty($state)) { array_push($errors, "State is required"); }
  15. if (empty($country)) { array_push($errors, "Country is required"); }
  16.  
  17. // register user
  18. if (count($errors) == 0) {
  19. $query = "INSERT INTO user (username, password, city, state, country)
  20. VALUES('$username', '$password', '$city','$state','$country')";
  21. mysqli_query($db, $query);
  22.  
  23. $_SESSION['username'] = $username;
  24. $_SESSION['success'] = "You Are now Logged In!";
  25. header('location: index.php');
  26. }
  27.  
  28. }
  29.  
  30. // LOG USER IN
  31. if (isset($_POST['login_user'])) {
  32. $username = mysqli_real_escape_string($db, $_POST['username']);
  33. $password = mysqli_real_escape_string($db, $_POST['password']);
  34.  
  35. if (empty($username)) {
  36. array_push($errors, "Username required");
  37. }
  38. if (empty($password)) {
  39. array_push($errors, "Password required");
  40. }
  41.  
  42. if (count($errors) == 0) {
  43. $query = "SELECT * FROM userinfo WHERE username='$username' AND password='$password'";
  44. $results = mysqli_query($db, $query);
  45.  
  46. if (mysqli_num_rows($results) == 1) {
  47. $_SESSION['username'] = $username;
  48. $_SESSION['success'] = "Welcome!";
  49. header('location: index.php');
  50. }else {
  51. array_push($errors, "Wrong username/password combination");
  52. }
  53. }
  54. }
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement