I have been trying to get this to work for a while now... All of the codes are in the same php page/file
<?php
$selectedoption = $_POST["selectedoption"];
$cookie_name = 'selected_option';
setcookie($cookie_name, $selectedoption, time() + (86400 * 30), "/");
if(!isset($_COOKIE[$cookie_name])) {
echo "Option not Selected";
} else {
echo "Option is " . $_COOKIE[$cookie_name];
}
?>
<form method="post" action="">
<input type="radio" name="selectedoption" value="option1"> Option 1<br>
<input type="radio" name="selectedoption" value="option2"> Option 2<br>
<input type="radio" name="selectedoption" value="option3"> Option 3<br>
<input type="radio" name="selectedoption" value="option4"> Option 4<br>
<input type="submit" name="submit" value="Submit">
</form>
Can cookies be set in the same file as the post? I am not sure if this is supposed to work like this, or if am doing something wrong. Thanks