How can I pass a multidimensional array using PHP from an HTML form to a MySQL database?
-
I am currently trying to build a web form here: http://gillianthonydance.com/dancealparty2012/index_2.php The radio buttons are in three sections as there are three users. I have managed to get the form working passing a single user's details to the mysql database but I cannot get my head around how to pass the $_POST multi-dimensional array to the Mysql Insert statement. I know the data is being passed to the processing page as I can generate a response using "echo $_POST". I have hunted the web but for the life of me cannot find an easy tutorial to walk me through this process. Can anyone recommend a good and thorough tutorial on this subject with clear coding examples?
-
Answer:
You can actually access whats inside your post variable. Example: If you have an input with the name="foobar" - then you can access that through $_POST['foobar'] To view the whole contents of your post variable, use the print_r() function Like this: <?php //Displays keys and their values of $_POST nicely echo '<pre>'; print_r($_POST); echo '</pre>'; ?> So solve the problem with storing data from a multidimensional array, you can either choose to store them individually if the structure and keys are fixed. If that's not the case, then you can serialize() the array, and store it that way. Then of course unserialize() when you fetch it again.
Dennis Micky Jensen at Quora Visit the source
Other answers
Hi, You can iterate through the multi dimensional array and insert data into the DB on each iteration. Please do a <?php dump($_POST); //use the function below. function dump($array){ echo '<pre>'; print_r(json_encode($array)); echo '</pre>'; } ?> Please post the json here, so that i can post asmall code smaple to iterate through the array. note: you can do a dump of the array itself, but i am too lazy to manually construc the array :), so Json would help! cheers, rajesh
Eswar Rajesh Pinapala
Related Q & A:
- How can I change a value in an array?Best solution by Stack Overflow
- how can I listen for database changes using java?Best solution by Stack Overflow
- How can I make a dynamic web page in PHP?Best solution by Yahoo! Answers
- In Visual Studio 2012 or 2013, how can I register a DLL file on Windows 7 64-bit computer using a Custom Action command?Best solution by Stack Overflow
- How can I parse a complex XML with PHP and CDATA?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.