anatak Posted May 27, 2010 Share Posted May 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/ Share on other sites More sharing options...
Alex Posted May 27, 2010 Share Posted May 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/#findComment-1064050 Share on other sites More sharing options...
anatak Posted May 27, 2010 Author Share Posted May 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/#findComment-1064058 Share on other sites More sharing options...
ixicoding Posted May 27, 2010 Share Posted May 27, 2010 http://www.php.net/manual/en/faq.html.php#faq.html.arrays May help you out a bit. Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/#findComment-1064059 Share on other sites More sharing options...
anatak Posted May 27, 2010 Author Share Posted May 27, 2010 aha thanks for the link ixicoding that will probably solve my problems (i hope) will report back Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/#findComment-1064060 Share on other sites More sharing options...
ixicoding Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/#findComment-1064062 Share on other sites More sharing options...
anatak Posted May 27, 2010 Author Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203068-passing-an-array-in-a-form/#findComment-1064073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.