Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = $_POST['username']; //username array in database.
- $password = $_POST['password']; //password array in database.
- //check if username and password exist on the database.
- if($username&&$password){
- $connect = mysql_connect("localhost", "root", "") or die ("Unable to connect."); //establish connection to server. I.E:("server", "server-user", "server-password")
- mysql_select_db("phplogin") or die ("Database does not exist."); // point to correct database no the server or, return with error.
- $query = mysql_query("SELECT * FROM users WHERE username='$username'"); //ask database to check username from the users table
- $numrows = mysql_numrows($query); //checks the location of the username on the database table
- if($numrows != 0){
- //verify user exists and provide appropiate credentials
- while($row = mysql_fetch_assoc($query));{
- $dbusername = $row['username'];
- $dbpassword = $row['password'];
- }
- //check to see if user provides valid information, else return error.
- if($username==$dbusername&&$password==$dbpassword){
- echo "Welcome! $username";
- }else
- echo "Incorrect Password.";
- }
- else
- die("That user does not exist, sorry.");
- }
- else
- die("Please enter a valid username and password.");
- ?>
Add Comment
Please, Sign In to add comment