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
Share on other sites

I'm not entirely sure what your main question is.

 

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

Yes.

 

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

Yes, use sessions

Link to comment
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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.