Trouble logging in with PHP/MySQL
<p>I'm trying to make a login page with php. My MySQL DB is:
<code>id, username, password, Role_ID</code>. </p>

<p>I have also created a field named Role that has the ID and the role (admin or user). </p>

<p>The problem is that when I try to login with a user that is registered, it just refreshes the login page instead of logging them in. </p>

<p>My code:</p>

<pre><code>&lt;?php 
// Connects to your Database 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("universiteti") or die(mysql_error()); 

//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
{
    //login and direct to the members page 
    $username = $_COOKIE['ID_my_site']; 
    $pass = $_COOKIE['Key_my_site'];

    $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());    
    while($info = mysql_fetch_array( $check ))  
    {
        if ($pass != $info['password']) 
        {
        }
        else
        {       
            // check the value of the 'status' in the db 
            if ($info['Roli_ID'] == '1') {              
                //go to admin area
                header("Location: admin.php");
            } else {
                //go to members area
                header("Location: raporti.php");  
            }
        }
    }
}

//if the login form is submitted 
if (isset($_POST['submit'])) 
{ 
    // makes sure they filled it in
    if(!$_POST['username'] | !$_POST['pass']) { die('please fill fields !'); }

    // checks it against the database
    if (!get_magic_quotes_gpc()) 
    {
    }

    $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'") or die(mysql_error());
    // Gives error if user dose not exist
    $check2 = mysql_num_rows($check);
    if ($check2 == 0) { die('This user does not exist. &lt;a href=registerfor.php&gt;register here &lt;/a&gt;'); }
    while($info = mysql_fetch_array( $check ))     
    {
        $_POST['pass'] = stripslashes($_POST['pass']);
        $info['password'] = stripslashes($info['password']);
        $_POST['pass'] = md5($_POST['pass']);

        //gives error if the password is wrong
        if ($_POST['pass'] != $info['password']) {
            die('Password i gabuar!please try again. &lt;a href=index.php&gt;Login here&lt;/a&gt;');
        }
        else 
        { 
            // if login is ok then we add a cookie 
            $_POST['username'] = stripslashes($_POST['username']); 
            $hour = time() + 3600; 
            setcookie(ID_my_site, $_POST['username'], $hour); 
            setcookie(Key_my_site, $_POST['pass'], $hour);  

            //Redirect them to the members area 
            header("Location: raporti.php"); 
        } 
    } 
} 
else 
{
?&gt;

&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post"&gt;  
  &lt;fieldset &gt;
    &lt;legend&gt;Login&lt;/legend&gt;
    &lt;input type='hidden' name='submitted' id='submitted' value='1'/&gt;
    &lt;label for='username' &gt;UserName*:&lt;/label&gt;
    &lt;input type='text' name='username'  maxlength="50" /&gt;
    &lt;label for='password' &gt;Password*:&lt;/label&gt;
    &lt;input type='password' name='pass' maxlength="50" /&gt;
    &lt;input type='submit' name='Submit' value='Log In' /&gt;
    &lt;a href="register.html"&gt;Register&lt;/a&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;
&lt;?php 
} 
?&gt;
</code></pre>

<p>I cant find the problem. I also want to show "Welcome {username}, Logout" at the top of the page after logging in but I dont know where to add the code.</p>
