Guest User

Untitled

a guest
Dec 25th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. $username = $_POST['username']; //username array in database.
  4. $password = $_POST['password']; //password array in database.
  5.  
  6. //check if username and password exist on the database.
  7. if($username&&$password){
  8. $connect = mysql_connect("localhost", "root", "") or die ("Unable to connect."); //establish connection to server. I.E:("server", "server-user", "server-password")
  9. mysql_select_db("phplogin") or die ("Database does not exist."); // point to correct database no the server or, return with error.
  10.  
  11. $query = mysql_query("SELECT * FROM users WHERE username='$username'"); //ask database to check username from the users table
  12.  
  13. $numrows = mysql_numrows($query); //checks the location of the username on the database table
  14.  
  15. if($numrows != 0){
  16. //verify user exists and provide appropiate credentials
  17. while($row = mysql_fetch_assoc($query));{
  18. $dbusername = $row['username'];
  19. $dbpassword = $row['password'];
  20.  
  21.  
  22. }
  23. //check to see if user provides valid information, else return error.
  24. if($username==$dbusername&&$password==$dbpassword){
  25. echo "Welcome! $username";
  26. }else
  27. echo "Incorrect Password.";
  28. }
  29. else
  30. die("That user does not exist, sorry.");
  31. }
  32. else
  33. die("Please enter a valid username and password.");
  34. ?>
Add Comment
Please, Sign In to add comment