Jump to content

Recommended Posts

 

 

....
<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?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/83669-solved-problem-with-serialize-function/
Share on other sites

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";}
}
?>

 

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

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.