I know that this is well known problem but I've tried all solutions with no avail :(
Here is my code:
<?php
ob_start();
if (!empty($_POST)) { // if submit
    $username = $_POST['username'];
    $userpass = $_POST['userpass'];
    mysql_connect('localhost', 'root', 'root') or die(mysql_error());
    mysql_select_db('ita4') or die($connection_error);
    function login($username, $userpass) {
        $sqlQuery = "SELECT COUNT(userid) FROM users WHERE name='$username' AND password='$userpass' AND admin='t'";
        $runQuery = mysql_query($sqlQuery);    
        return (mysql_result($runQuery, 0) == 1) ? TRUE : FALSE; 
    }
    if(login($username, $userpass)) {
        setcookie("username", $username, time()+60*60*24*30);
        $_COOKIE['username'] = $username;
        echo "Me:".$_COOKIE['username'];
        //echo "<script> location.replace('done.html'); </script>";
    } else {
        echo "<script> alert('Your input data is not found!'); </script>";
    }
}
?>
<html>
<head>
    <title>Login</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta http-equiv=content-type content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="upper">
<a href="index.html">Home</a>  •  <a href="login.html">Login</a>  •  <a href="about.html">About</a>
</div>
<div id="container">
    <div id="loginDiv">
        <form action="login.php" onsubmit="return checkEmpty()" method="post" name="loginForm">
            <table>
                <tr>
                    <td style="width:100px">Name: </td>
                    <td>
                    <input name="username" id="username" type="text" style="width:250px"></td>
                </tr>
                <tr>
                    <td style="width:100px">Password: </td>
                    <td>
                    <input name="userpass" id="userpass" type="password" style="width:250px"></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align:center"><input id="loginImg" type="image" src="images/loginButton.png"></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div id="lower">
    <br><br><br><br><br>
    <p style="text-align:center">COPYRIGHTS © 2013   •   WWW.HISHAM.WS</p>
</div>
<script type="text/javascript">
function checkEmpty() {
    var username = document.getElementById("username").value;
    var userpass  = document.getElementById("userpass").value;
    if(username=="" || username==null) { alert("You've to enter your name!"); }
    else if(userpass=="" || userpass==null) { alert("You've to enter a password!"); }   
    else { return true; } 
    return false; 
}
</script>
</body>
</html>
Thanks in advance
 
     
     
     
     
     
    