0

Below is a sample of a cell from a table in a form.

There's multiple, similar cells per table row, and there can be multiple rows in the table.

I want to post each row to a different page, and then be able to cycle through each row. So far I've written this for each cell:

<td><?php echo "$inkrementering";?><input type="hidden" name="historik[]" value="<?php echo serialize($inkrementering);?>"></td>
                    <?php 

             } 
             }
                ?>
    </tr>
</table>           
   <input type="submit" value="Gem træning" name="submit">
</form>

On the recipient page, I have the following code:

foreach ($_POST['historik'] as $historikArray)
   {
echo unserialize($historikArray)[3];    
   }

which has the purpose of:

1) Cycling through all rows, one by one

2) Printing the item in place [3] from each row (just as an example...)

But, I'm getting the error: Notice: unserialize(): Error at offset 0 of 4 bytes

Anyone know how to fix this?

Or, maybe I'm not on the right track using serialize...?

Any help appreciated! :)

  • possible duplicate of [unserialize() \[function.unserialize\]: Error at offset](http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset) – Ohgodwhy Oct 11 '14 at 19:27

1 Answers1

0

You are recieving a notice because something is wrong with the serialized data. You did not post it so I'm unsure how it's malformed however...

maybe I'm not on the right track using serialize

It is not recommended to unserialize user submitted data. This is due to the possibility of a user changing the class that the data should be unserialized into which may have security ramifications (especially if there is a __wakeup() magic method defined).

If you want to encapsulate complex structure you can use JSON instead. This has the added benefit of both the client and the server having native functions that can work with the same data format.

webbiedave
  • 48,414
  • 8
  • 88
  • 101