I have a checkbox that when I click I want it to set a cookie with a value of an array. But when I click on the checkbox it doesn't set my cookie.
I don't understand why it is not being set. Is there something wrong with how I am creating the array for the value of the cookie?
Here is my code:
 extract($_POST);
 $code = $_POST['code'];
 $total= 100;
 if(isset($save)){
        echo "Saved";
        $cookie = array(
            'name'   => $code,
            'value'  => $total,
    );
    setcookie("cookie",json_encode($cookie),86500);
}
 if(isset($_COOKIE['cookie'])){
        echo "SET";
    }else{
        echo "NOT SET";
    }
<form method='post'>
     <input type="checkbox" name="save" value="1">Save
     <input name='code' />
</form
 
    