Suchy Posted December 30, 2007 Share Posted December 30, 2007 .... <label><input type="checkbox" name="type[]" value="13">People</label><br> <label><input type="checkbox" name="type[]" value="14">Erotica</label><br> <label><input type="checkbox" name="type[]" value="16">Nature</label><br> .... <?php ..... $type1 = ($_POST['type']); if ($type1 == 14) / $type = serialize(14); // field should have: a:1:{i:0;s:2:"14";} else $type = serialize($type1); // field should have a:3:{i:0;s:2:"01";i:1;s:2:"02";i:2;s:2:"07";} or other ..... ?> The problem is that if I select erotica (type 14) other types are also selected and stored in the db, how can I fix this? Quote Link to comment https://forums.phpfreaks.com/topic/83669-solved-problem-with-serialize-function/ Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 issue in your if statement <?php $type1 = ($_POST['type']); if ($type1 == 14){ $type = serialize(14); // field should have: a:1:{i:0;s:2:"14"; } else{ $type = serialize($type1); // field should have a:3:{i:0;s:2:"01";i:1;s:2:"02";i:2;s:2:"07";} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83669-solved-problem-with-serialize-function/#findComment-425641 Share on other sites More sharing options...
teng84 Posted December 30, 2007 Share Posted December 30, 2007 i think your condition always falls under your else because $type1 is an array and obviously array is not equal to any numbers or string... i think you should not use if since your using array just use foreach instead then serialize it one by one since this is checbox not radio button you're expecting the form to be selected on the same time Quote Link to comment https://forums.phpfreaks.com/topic/83669-solved-problem-with-serialize-function/#findComment-425644 Share on other sites More sharing options...
Suchy Posted December 30, 2007 Author Share Posted December 30, 2007 did something else that works for me: .... <label><input type="checkbox" name="type[]" value="13">People</label><br> <label><input type="checkbox" name="type[]" value="x">Erotica</label><br> <label><input type="checkbox" name="type[]" value="14">Nature</label><br> .... if (isset($_POST['type'])) $type1 = join(',',($_POST['type']) ); if (strstr ($type1, "x")) $type= "x"; else $type= $type1; Quote Link to comment https://forums.phpfreaks.com/topic/83669-solved-problem-with-serialize-function/#findComment-425752 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.