Topic: mysql integration worked, need assistance with cookies

basically on my site so far, I have successfully merged the databases together, however when you login of course the cookie is not set or saved.

how I check my sessions on my site are with the $_SESSION[username] and $_SESSION[password] looking on the functions for check cookie has me a bit confused on how i could fuse them together.

here is my code to check the user

function valid_user($username, $password) {
    global $md5salt;
    $sql = "SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."' AND password='".md5($password.$md5salt)."'";
    $rs = mysql_query($sql);
    return mysql_valid($rs);
}

function check_login($username, $password, $redirect = "") {
    $valid = valid_user($username, $password);

    if (!$valid) {
        header("Location: index.php?check=failed");
        exit();
    }
    else {
        if ($redirect) {
            header("Location: $redirect");
            exit();
        }
    }
}