Tuesday, September 17, 2013

Using radio button to set cookie preferences?

Using radio button to set cookie preferences?

I have these 4 radio buttons in which i am submitting to a
validatepreferences.php which is the php code below however i am
struggling to understand why when i click submit nothing is going through
the if statement therefore not giving me my cookie in which to change
images based on user input
<input type="radio" name="radioimage"><img class="prefimage"
src="../images/image1.jpg">
<br>
<input type="radio" name="radioimage"><img
class="prefimage" src="../images/image2.jpg">
<br>
<input type="radio" name="radioimage"><img
class="prefimage" src="../images/image3.jpg">
<br>
<input type="radio" name="radioimage"> No Picture
I think the php code must have an error or my if is not right altough i
cannot see it.
<?php
if(isset($_POST['radioimage'])){
$radioimage = $_POST['radioimage'];
if ($radioimage == "0" || $radioimage == "1" || $radioimage == "2"
|| $radioimage =="3") {
setcookie("image", $radioimage, time()+300);
}
?>

No comments:

Post a Comment