Need to store multiple array from form to mysql

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat Feb 23, 2013 2:22 am

Need to store multiple array from form to mysql

Postby kleidi » Sat Feb 23, 2013 2:41 am

I have an html form that, via javascript, depending on the user selection, appears some input fields in a row. This is the javascript:

Code: Select all

function addInputAdult(num){
for(xAdult=0;xAdult<num;xAdult++)inputElementsAdult.innerHTML=inputElementsAdult.innerHTML +'<table width="100%" style="margin:0; padding:0;"><tr><th width="24%" scope="col">Adult '+(xAdult + 1)+' - Name</th><th width="13%" scope="col">Birthdate</th><th width="18%" scope="col">Place of Birth</th><th width="13%" scope="col">Passport Nr</th><th width="13%" scope="col">Issue Date</th><th width="16%" scope="col">Expiry Date</th></tr><tr><td> <input name="adlt[][Emri]" type="text" id="adltEmri" style="width:98%;" /></td><td> <input style="width:95%;" type="text" name="adlt[][Dtlindja]" id="adltDtlindja" /></td><td> <input style="width:90%;" type="text" name="adlt[][Vendlindja]" id="adltVendlindja" /></td><td> <input style="width:90%;" type="text" name="adlt[][Pass]" id="adltPass" /></td><td> <input style="width:90%;" type="text" name="adlt[][DtLeshimit]" id="adltDtLeshimit" /></td><td><input style="width:90%;" type="text" name="adlt[][DtSkadimit]" id="adltDtSkadimit" /></td></tr></table>';

So, the user make the selection and the form appears. Now, i want to add the user input details in my mysql database. Can you help me on this please? I'm not "sure" how to do this.

My problem is on getting the informations from the form in a way that those information could be usable and understandable. What i have tried is:

Code: Select all

foreach ( $_POST['adlt'] as $adult) {
echo $getd;

...but it shows all the information not separated and I don't know how to separate informations from each other. Output looks like this:

Code: Select all

adult1 Nameadult1Birthdateadult1Passportadult1PlaceofBirthadult1IssueDateadult1expirydateadult2 Nameadult2 Birthdate...and so on

Can you help me on this, please?

Thank you in advance

User avatar
New php-forum User
New php-forum User
Posts: 16
Joined: Wed Feb 27, 2013 2:49 am
Location: Dhaka, Bangladesh

Re: Need to store multiple array from form to mysql

Postby kiash001 » Wed Feb 27, 2013 3:26 am

I'm not clear about you!
I think you want to store your forms in MySQl Database. If I right you need to encode your form data into JSON. For encoding and decoding you have to use json_encode() and json_decode()

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 7 guests