Advertisement
Guest User

jordan look

a guest
Mar 29th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2. //Set up credentials
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $database = "users";
  7.  
  8. // Create connection
  9. $link = mysqli_connect($servername, $username, $password, $database);
  10.  
  11. // Check connection
  12. if (!$link) {
  13. die("Connection failed: " . mysqli_connect_error());
  14. }
  15.  
  16. //Start query
  17. $username = $_POST['username'];
  18. $password = $_POST['password'];
  19. $sql = "SELECT * FROM userdata WHERE username='$username'";
  20. $result = $link->query($sql);
  21. //Count number of row with that username
  22. $count=mysql_num_rows($result);
  23. //if only one match then...
  24. if($count==1){
  25. $row = mysql_fetch_assoc($result);
  26. if(crypt($password,$row['password']) == $row['password']){
  27. session_register("username");
  28. session_register("password");
  29. echo "Login Successful";
  30. return true;
  31. }
  32. else {echo "Wrong username or password";
  33. return false;
  34. }
  35. }
  36. else {
  37. echo "Wrong username or password";
  38. return false;
  39. }
  40. if ($link->query($sql) === TRUE) {
  41. echo "","<br>";
  42. } else {
  43. echo "Error updating record: " . $link->error;
  44. }
  45.  
  46.  
  47.  
  48. $result->close();
  49. $link->close();
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement