0

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?

2
  • 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. Commented Jul 2, 2013 at 9:54
  • Iserni - any ideas why/ how it got serialized twice? Commented Jul 2, 2013 at 9:55

1 Answer 1

2

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));
Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.