Location: PHPKode > scripts > PHP Address book > php-address-book_v_1.02_eng/login.php
<?php 
$doc = "login";
include_once 'includes/header.inc.php'; 

//receive form
if(isset($_POST['submit'])){
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    $correct = false;
    
    $query = $mysqli->prepare("SELECT 
                                    `cal_users`.`id`,
                                    `cal_users`.`role`,
                                    `cal_users`.`username`,
                                    `cal_users`.`password`
                               FROM 
                                    `cal_users` 
                               WHERE 
                                    `username` = ? 
                               AND 
                                    `password` = ?
                               ");
    $query->bind_param(ss, $username, $password);
    $query->bind_result($s_id,$s_role,$s_username,$s_password);
    $query->execute();
    
    while($query->fetch()){  
        $_SESSION['userid'] = $s_id;
        header("location: index.php");
    }
    $query->store_result();
    
    if($correct == false){
        ?>
        <div class="alert alert-error">
            Username or password are wrong
        </div>
        <?php
    }
}
?>
    <form class="well form-inline" method="post" action="">
        <input type="text" class="input-small" placeholder="Username" name="username">
        <input type="password" class="input-small" placeholder="Password" name="password">
        <button type="submit" class="btn" name="submit">Sign in</button>
    </form>
	<div class="span7">
		<p>username: demo</p>
		<p>password: demo</p>
	</div>
<?php include_once 'includes/footer.inc.php'; ?>
Return current item: PHP Address book