I try to set a cookie for 2 radio buttons and i don’t know what i do wrong. I need to make it when a button is checked to remain checked even the page is refreshed. Can someone give me an advice with this? Thanks
This is my test.php
<?php
if(isset($_POST['radio1'])) {
setcookie('radio1', true, 600, '/');
setcookie('radio2', false, 600, '/');
} else if(isset($_POST['radio2'])) {
setcookie('radio2', true, 600, '/');
setcookie('radio1', false, 600, '/');
}
?>
<form method="POST" action="test.php">
<div id="radio">
<input type="radio" id="radio1" name="radio" checked="checked" />
<label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" />
<label for="radio2">Choice 2</label>
</div>
</form>
I don’t quite follow your code, but the following should check the correct radio button for you: