<?php
    session_start
();

    
$errorMessage '';

    if (isset(
$_POST['txtUserId']))
    {
        
$userID htmlentities($_POST['txtUserId']);
        
$userPass htmlentities($_POST['txtPassword']);

        
//replace the following with your MySQL values
        //*********************
        
$dbhost "localhost";
        
$dbuser "user";
        
$dbpass "pass";
        
$dbname "test";

        
//*********************

        
$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
        
mysql_select_db($dbname);

        
// check if the user id and password combination exist in database
        
$query "SELECT * FROM tbluser WHERE `Username` = '$userID' AND `password` = PASSWORD('$userPass') AND `enabled`=1";


        
$result =mysql_query($query) or die('Query failed. ' mysql_error());

       if (
mysql_num_rows($result) == 1)
       {
          
// the user id and password match,
          // set the session
            
$_SESSION['test_logged_in'] = true;
            
$_SESSION['user']=$userID;

         
// after login we move to the main page
         
exit;
       }
       else 
$errorMessage 'Sorry, wrong user id / password';
    }

    if (
$errorMessage != '') {
    
?>
            <p align="center"><strong><font color="#990000"><?php echo $errorMessage?></font></strong></p>
            <?php
    
}
?>

<form id="frmLogin" name="frmLogin" method="post">
    <table width="400" cellspacing="2" cellpadding="2" border="0" align="center">
        <tbody>
            <tr>
                <td width>User Id</td>
                <td><input type="text" id="txtUserId" name="txtUserId" /></td>
            </tr>
            <tr>
                <td width>Password</td>
                <td><input type="password" id="txtPassword" name="txtPassword" /></td>
            </tr>
            <tr>
                <td width>&nbsp;</td>
                <td><input type="submit" value="Login" name="btnLogin" /></td>
            </tr>
        </tbody>
    </table>
</form>