Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
2  
Looks like data that has been serialized twice. "s:55:", as a string, is five characters long, and so becomes s:5:"s:55:";. Verify your serializing workflow. –  lserni Jul 2 '13 at 9:54
    
Iserni - any ideas why/ how it got serialized twice? –  Homer_J Jul 2 '13 at 9:55

1 Answer 1

up vote 2 down vote accepted

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));
share|improve this answer
    
steven - thanks for this - I guess what I find odd is that I'm only serializing the numbers 1234567 as you can see, not text or long text etc. Really appreciate the heads up on using base64 to encode/ decode. Will try it! –  Homer_J Jul 2 '13 at 10:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.