Cookies not saving (PHP)

My cookies are not saving, I am using PHP 5.
Code:

require 'dbcon.php';
$sql = "SELECT * FROM accounts";
$result = $conn->query($sql);
$username = $_POST['username'];
$password = $_POST['password'];
$row = mysql_fetch_row($result);

setcookie("ID6", $row['ID'], time() + 60*60*24*31*12, "/") or die("Cookie could not be set. <a href='index.php'>Try again!</a>"); 

if(!isset($_POST['username']) || !isset($_POST['password'])) {
    header("Location: index.php");
    exit();
}
 while($row = mysqli_fetch_assoc($result)) {
    if($username == $row['username']) {
        if($password == $row['password']) {

        if($row['accdel'] == 1) {
            echo("You are banned.");
            exit(); 
            }
            echo "Logged in with cookie:" . $_COOKIE['ID6'];
            exit();

        }
        else {
            echo "The account does not exist, or you have put in the wrong log in.";
            exit();
        echo"That's not an account name though...";}
    }
}


?>

Please help. Is the selected sql even a settable cookie value? (Please make it simple. I do not know much about php nor cookies.

One thought on “Cookies not saving (PHP)”

Leave a Reply

Your email address will not be published.