Advertisement
jksutradhor

try

Dec 23rd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. $username = "";
  6. $email = "";
  7. $errors= array();
  8.  
  9. $con=mysqli_connect('localhost','root','','user');
  10.  
  11. if(isset($_POST['register'])) {
  12. $username = mysqli_real_escape_string($con, $_POST['username']);
  13. $email = mysqli_real_escape_string($con, $_POST['email']);
  14. $password_1 = mysqli_real_escape_string($con, $_POST['password_1']);
  15. $password_2 = mysqli_real_escape_string($con, $_POST['password_2']);
  16.  
  17.  
  18.  
  19. if (empty($username)) {
  20. array_push($errors,"Username is required");
  21. }
  22.  
  23. if (empty($email)) {
  24. array_push($errors, "User email is required");
  25. }
  26.  
  27. if (empty($password_1)) {
  28. array_push($errors, "User Password is required");
  29. }
  30.  
  31. if ($password_1 != $password_2) {
  32. array_push($errors, "Password did not match");
  33. }
  34.  
  35.  
  36. if (count($errors) == 0) {
  37.  
  38. $password = md5($password_1);
  39.  
  40. $sql="INSERT INTO user (username, email, password) VALUES ('$username','$email','$password')";
  41. mysqli_query($con, $sql);
  42. $_SESSION['username'] = $username;
  43. $_SESSION['success'] = "You are now Registered.";
  44. header('location: confo.php');
  45.  
  46. }
  47.  
  48.  
  49. if (isset($con, $_POST['login'])) {
  50. $username = mysqli_real_escape_string($con, $_POST['username']);
  51. $password = mysqli_real_escape_string($con, $_POST['password']);
  52.  
  53.  
  54.  
  55. if (empty($username)) {
  56. array_push($errors,"Username is required");
  57. }
  58.  
  59. if (empty($password)) {
  60. array_push($errors, "Valid password is required");
  61. }
  62.  
  63. if (count($errors) == 0) {
  64. $password = md5($password);
  65. $query = "SELECT * FROM regi WHERE username='$username' AND password='$password' ";
  66. $result = mysqli_query($con, $query);
  67. if (mysqli_num_rows($result) == 1) {
  68. $_SESSION['username'] = $username;
  69. $_SESSION['success'] = "You are now Registered.";
  70. header('location: confo.php');
  71. }else{
  72. array_push($errors, "The username/password did not match");
  73. }
  74. }
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81. if (isset($_GET['logout'])) {
  82. session_destroy();
  83. unset($con, $_SESSION['username']);
  84. header('location: login.php');
  85. }
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement