Jump to content

Passing array variable through $_POST via serialize


webent

Recommended Posts

Hi all, I'm trying to pass an array variable through my form and according to all the information I have found, it says to use serialize... but when I actually implement it, it doesn't work... Here's what I've done...

 

// Prior to the loop I initialize the array and set the counter
$line_item = array();
$item_counter = 1; 

// Here's my array in the loop
$line_item[$item_counter][id] = $sub_row['SKU'];
$line_item[$item_counter][description] = $sub_row['PRODUCT_NAME'];
$line_item[$item_counter][quantity] = $row['shopping_cart_contents_qty'];
$line_item[$item_counter][price] = $individual_price;     

$item_counter++;

// Later, outside the loop, I serialize the array
$serialized_items = serialize($line_item);

// Then for testing purposes, I unserialize it and check to make sure it still looks pretty
echo '<pre>';
$individual_rows = unserialize($serialized_items);
print_r ($individual_rows);
echo '</pre>';

 

With this, it works perfectly, but when I stick the serialized array into a form and pass it, like so...

<input type="hidden" name="line_items" value="<? echo $serialized_items; ?>"> 

// Then on the receiving page, that the form is posted to...
$line_item = unserialize($_POST['line_items']);
echo '<pre>';
print_r ($line_item);
echo '</pre>';

 

Nothing, nada... This is supposed to work, right, or did I do something wrong?

You know, I got to thinking, perhaps it isn't wise to be passing all of this data anyway... I mean, it's all in a shopping cart basket in a db anyway, why not just extract it on the other side... Duh! LOL... Be alot more secure...

 

But doesn't it raise an interesting question as to why this doesn't work?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.