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.

1
  • 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. Commented Nov 26, 2018 at 6:37

1 Answer 1

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 agree to our terms of service and acknowledge you have read our privacy policy.

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