Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host="localhost"; // Host name
- $username="Any"; // Mysql username
- $password=""; // Mysql password
- $db_name="phploginhw"; // Database name
- $tbl_name="phpro_users"; // Table name
- // Connect to server and select databse.
- $mysqli = mysqli_connect("$host", "$username", "", "$db_name")or die("cannot connect");
- // username and password sent from form
- $loginusername = $_POST['user'];
- $loginpassword = $_POST['pass'];
- $query = "SELECT * FROM $tbl_name WHERE phpro_username='$loginusername' AND phpro_password='$loginpassword'";
- $result = mysqli_query($mysqli, $query) or die(mysqli_error());
- $count = mysqli_num_rows($result);
- // If result matched $username and $password,number of rows in result query must be 1 row
- if($count == 1){
- // Register $username, $password and redirect to file "login_success.php"
- session_start();
- $_SESSION['loginusername'] = $loginusername;
- $_SESSION['loginpassword'] = $loginpassword;
- header("location:login_success.php");
- }
- // If $count does not = 1 then displays error and links back to login page
- else {
- echo "Wrong Username or Password";
- echo "<p><a href=\"Login.html\"> Return to Login </a></p>";
- }
- ?>
Add Comment
Please, Sign In to add comment