hhex50 Posted August 8, 2009 Share Posted August 8, 2009 hi everyone im a newbie i wrote this code but the cookies are not being read...the variables part is working fine but having problem with cookies first code is is the one i wrote........i copied the 2nd one frm another location....2nd codes works fine...but i m not able to find any difference between 1st and 2nd code...... 1ST code <?php if ($_POST['type_sel']) { setcookie("font[type]", $_POST['type_sel'], time()+3600); } if ($_POST['size_sel']) { setcookie("font[size]", $_POST['size_sel'], time()+3600); } $type=array("arial","verdana","courier","helevetica"); $size=array("1","2","3","4","5","6","7"); echo "<html><head><title>Cookie Test</title></head><body><div align='center'>"; echo "<form method='POST'>"; echo "Enter Desired font "; echo "<select name='type_sal'>"; echo "<option selected value=''>default</option>"; foreach($type as $var){ echo "<option>$var</option>"; } echo "</select><br><br>"; echo "Enter Desired size "; echo "<select name='size_sal'>"; echo "<option selected value=''>default</option>"; foreach($size as $var){ echo "<option>$var</option>"; } echo "</select><br><br>"; echo "<input type='submit' value='Get cookie'>"; echo "</form><br>"; echo "<b>Your cookies say:</b><br>"; [font=georgia][color=red]this is the cookies part where i think the problem is but i cant figure it out[/color][/font] echo "<font "; if ($_COOKIE["font"]["type"]) { $cookie_font_type = $_COOKIE["font"]["type"]; echo "face=$cookie_font_type "; } if ($_COOKIE['font']['size']) { $cookie_font_size = $_COOKIE['font']['size']; echo "size='$cookie_font_size' "; } echo ">"; echo "\$font[type] = $cookie_font_type<br>"; echo "\$font[size] = $cookie_font_size<br>"; echo "</font><br>"; echo "<b>Your form variables say:</b><br>"; echo "<font "; echo "<b>Your variables say: </b><br>"; echo "<font "; if($_POST['type_sal']){ $post_type_sel=$_POST['type_sal']; echo "face='$post_type_sel'"; } if($_POST['size_sal']){ $post_size_sel=$_POST['size_sal']; echo "size='$post_size_sel'"; } echo ">"; echo "\$type_sel=$post_type_sel<br>"; echo "\$size_sel=$post_size_sel<br>"; echo "</font><br><br>"; echo "</div></body></html>"; ?> 2nd code <?php //cookies.php if ($_POST['type_sel']) { setcookie("font[type]", $_POST['type_sel'], time()+3600); } if ($_POST['size_sel']) { setcookie("font[size]", $_POST['size_sel'], time()+3600); } $type = array("arial", "helvetica", "sans-serif", "courier"); $size = array("1","2","3","4","5","6","7"); echo "<html><head><title>Cookie Test</title></head><body><div align='center'>"; echo "<form method='POST'>"; echo "What font type would you like to use?"; echo "<select name='type_sel'>"; echo "<option selected value=''>default</option>"; foreach ($type as $var) { echo "<option>$var</option>"; } echo "</select><br><br>"; echo "What font size would you like to use?"; echo "<select name='size_sel'>"; echo "<option selected value=''>default</option>"; foreach ($size as $var) { echo "<option>$var</option>"; } echo "</select><br><br>"; echo "<input type='submit' value='Get Cookies'>"; echo "</form>"; echo "<b>Your cookies say:</b><br>"; echo "<font "; if ($_COOKIE["font"]["type"]) { $cookie_font_type = $_COOKIE["font"]["type"]; echo "face=$cookie_font_type "; } if ($_COOKIE['font']['size']) { $cookie_font_size = $_COOKIE['font']['size']; echo "size='$cookie_font_size' "; } echo ">"; echo "\$font[type] = $cookie_font_type<br>"; echo "\$font[size] = $cookie_font_size<br>"; echo "</font><br>"; echo "<b>Your form variables say:</b><br>"; echo "<font "; if ($_POST[type_sel]) { $post_type_sel = $_POST[type_sel]; echo "face='$post_type_sel' "; } if ($_POST[size_sel]) { $post_size_sel = $_POST[size_sel]; echo "size='$post_size_sel' "; } echo ">"; echo "\$type_sel = $post_type_sel<br>"; echo "\$size_sel = $post_size_sel<br>"; echo "</font>"; echo "</div></body></html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169356-cookies-not-bein-read/ Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 You've named your select tags wrong echo "<select name='type_sal'>"; echo "<option selected value=''>default</option>"; foreach($type as $var){ echo "<option>$var</option>"; } echo "</select><br><br>"; echo "Enter Desired size "; echo "<select name='size_sal'>"; You've named them size_sal and type_sal. You're ment to name them as size_sel and type_sel. Quote Link to comment https://forums.phpfreaks.com/topic/169356-cookies-not-bein-read/#findComment-893683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.