Forum Moderators: coopster

Message Too Old, No Replies

Data serialisation

Storing Serialize data

         

ev11

7:07 am on Oct 2, 2010 (gmt 0)

10+ Year Member



Hello,
I have a very large form and i want to serialize part of the form for storing in mysql.I am just a starter,can someone help me or know a tutorial?

penders

10:37 am on Oct 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi ev11 - have a look at PHP's serialize() [uk.php.net] function.

ev11

6:38 am on Oct 4, 2010 (gmt 0)

10+ Year Member



Hi Penders, sorry wasn't really clear...

well i have some group of radio buttons,
eg :

<input type="radio" name="imd2" id="imd24" value="4">
<input type="radio" name="imd2" id="imd23" value="3">

<input type="radio" name="imd3" id="imd34" value="4">
<input type="radio" name="imd3" id="imd33" value="3">

<input type="radio" name="imd3" id="imd34" value="4">
<input type="radio" name="imd3" id="imd33" value="3">

That i want to serialize. cant figure how to POST the 3 values and serialize it.

penders

2:40 pm on Oct 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I assume your last 2 radio button controls should have the name 'imd4'?

To serialize these 3 values, then you could do something like the following when you are processing the form submission:

$data_to_serialize = array(); 
if (isset($_POST['imd2'])) {$data_to_serialize['imd2'] = $_POST['imd2'];}
if (isset($_POST['imd3'])) {$data_to_serialize['imd3'] = $_POST['imd3'];}
if (isset($_POST['imd4'])) {$data_to_serialize['imd4'] = $_POST['imd4'];}
$serialized_data = serialize($data_to_serialize);
echo $serialized_data;


The serialized data is a string of the form:
a:3:{s:4:"imd2";s:1:"4";s:4:"imd3";s:1:"3";s:4:"imd4";s:1:"4";}

that you can save in your database, recall later and unserialize() to perhaps repopulate your form or whatever.