Jump to content

passing an array in a form


anatak

Recommended Posts

Hello,

 

I have a form that I use to edit text entries from a database.

the form passes the data through a script that checks if the passed data is different (edited) than the data in the database.

 

I am trying to make the $_POST array identical to the array I get from the database but I can not seem to make this work correctly.

 

Is it possible to make the $_POST array a multidimensional array ?

Or is there a way to pass an array from one page to the other ?

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/
Share on other sites

I would prefer not to use sessions

so how can I make the $_POST array into a multidimensional array ?

 

Could you give me an example how to build a multidimensional $_POST array ?

 

e.g.

$_POST array

[0]

    [name]=Thomas

    [age]=21

 

[1]

    [name]=Teddy

    [age]=15

 

I have no idea how to do this.

I tried with a form with <input type="text" name="[0][name]" value="thomas">

but that did not work.

 

thank you

anatak

 

If it doesn't solve it hopefully it helps ;) .. It's an overview on passing arrays to php directly from a form. It doesn't go into multi dimensional arrays but you may be able to specify i.e.

<input type="text" name="myArray['Myarray2'][]" /> for passing it in multi dimensional.

Problem solved

 

so if someone is looking how to create a multiple dimensional array in html here is an example

$i=0

<input type="hidden" name="$i[]" value="$i">

<input type="text" name="$i[name]" value="thomas">

<input type="text" name="$i[age]" value="25">

$i=1

<input type="hidden" name="$i[]" value="$i">

<input type="text" name="$i[name]" value="teddy">

<input type="text" name="$i[age]" value="15">

 

of course you have to escape the $variables this is just meant as a help to people struggling with arrays. (like I do)

 

thank you ixicoding for the link.

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.