Jump to content

[SOLVED] Problem with serialize function


Suchy

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.