简体   繁体   中英

PHP Array - Odd data when saving to MySQL

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?

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM