After registration on my site the activation link sets a field 'activated' in the table to 1 from 0. So unless a user clicks on the activation link, he/she should not be able to login, but for some reason login function is still executing and activation is of no use, I have even tried the AND condition in the query but no use, can someone please help me with my code.
function login()
{   
if(isset($_POST['submit']))
{
    $db = new Connection(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    if($username == '')
    {
        setMessage('Sorry you did not enter a username.', 0);
        header('Location: '.BASE_URL.'dashboard/login');
        exit;
    }
    elseif($password == '')
    {
        setMessage('Sorry, you did not enter a password.', 0);
        header('Location: '.BASE_URL.'dashboard/login');
        exit;
    }
    else
    {
        $result = $db->query('
        SELECT ID, name, email, password, type, activated, suspended, count
        FROM users
        WHERE email = "'.$username.'"
        LIMIT 1
        ');
        $totalRows = mysql_num_rows($result);
        if($totalRows == 1)
        {
            while($row = mysql_fetch_assoc($result))
            {
                if(verifyPassword($password, $row['password']) == TRUE)
                {
                    if($row['activated'] == 0)
                    {
                        setMessage('You have not activated your account.', 0);
                        header('Location: '.BASE_URL.'dashboard/login');
                        exit;
                    }
                    if($row['suspended'] == 1)
                    {
                        setMessage('Your account is suspended. You may request to have your account restored by sending us a message on the Contact us page of newtongrads.com.', 0);
                        header('Location: '.BASE_URL.'dashboard/login');
                        exit;
                    }
                    if($row['type'] != 'ADMIN')
                    {
                        setMessage('You don\'t have enough privileges to access this page.', 0);
                        header('Location: '.BASE_URL.'dashboard/login');
                        exit;
                    }
                    else
                    {
                        $_SESSION['admin']['sessionID'] = base64_encode(date('Ymdhis'));
                        $_SESSION['admin']['userID'] = $row['ID'];
                        $_SESSION['admin']['email'] = $row['email'];
                        $_SESSION['admin']['type'] = $row['type'];
                        $_SESSION['admin']['fullName'] = getName($row['ID']);
                        $_SESSION['admin']['profileImage'] = $row['ID'];
                        setcookie('username', $username, time() + (86400 * 7));
                        //setcookie('password', $password, time() + (86400 * 7));
                        //$row['type'];
                        $query = 'UPDATE users
                        SET count = "'.($row['count']+1).'"
                        WHERE ID = "'.$row['ID'].'"';
                        $db->query($query);
                        setMessage('Successfully logged in.', 1);
                        header('Location: '.BASE_URL.'dashboard/home');
                        exit;
                    }
                }
                else
                {
                    setMessage('Sorry, you have entered an incorrect password.', 0);
                    header('Location: '.BASE_URL.'dashboard/login');
                    exit;
                }
            }
        }
        else
        {
            setMessage('Sorry, no user exists with that username.', 0);
            header('Location: '.BASE_URL.'dashboard/login');
            exit;
        }
    }
}
}
 
     
    