2

Please help advice. How to save multiple Fields in the database. I have a form with X number of fields. Fields added using JQuery

<input type="text" value="" name="jform[phone]">
<input type="text" value="" name="jform[phone]">
<input type="text" value="" name="jform[phone]">

In models I get $data['phone'], but I can not save it in the database. What is the best way to save multiple Fields in the database.

  • This question is too light on details and effort. Please improve this question. I would like to tell you to add a pair of square brackets to the name value (jform[phone][]) but then that would only be half of the job. We don't know anything about your database table or how you wish to store the data. You haven't shown any coding attempt at all. – mickmackusa Nov 26 '18 at 6:37
1

Try serializing the array before saving it to the database, and then, when you need it, you can unserialize it (you can do this using the serialize, unserialize functions).

You can also save the array as json (which is a better option) using the json_encode PHP function and then, when you want to retrieve it from the database, then you can use json_decode.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.