Reputation: 3323
I have a PHP array that I am saving to a MySQL Database:
$q35list = serialize($_POST["q35list"]);
Using mysqli_prepare
I am saving successfully to the database.
What is odd is that I have a mix of data being stored:
s:0:"";
- fine as user has not selected anything.
s:55:"Set[]=6&Set[]=4&Set[]=3&Set[]=7&Set[]=2&Set[]=5&Set[]=1";
- fine as user has selected options and this appears correctly saved.
But, I am getting a few odd ones, that I can neither replicate or understand how/what/why this is being saved:
s:4:"s:4:";
s:5:"s:55:";
s:4:"s:8:";
Has anyone come across this/ know what this might be and would be kind enough to provide an explanation?
Upvotes: 0
Views: 89
Reputation: 4875
its hard to say what happend here but it looks like a double serialisation with errors.
The most common way to avoid problems with serialisation is to base64 encode after serialisation before save to db:
//serialize
$string = base64_encode(serialize($array));
//unserialize
$array = unserialize(base64_decode($string));
Upvotes: 2