0

I have the following:

<form method="POST" action="<?php echo site_url('admin/updateCoursesIn'); ?>">
    <input type="text" value="1" name="values">
    <input type="text" value="2" name="values">
    <input type="text" value="3" name="values">

    <input type="submit" value="Submit">
</form>

Function in codeigniter:

public function updateCoursesIn($from = "") {
            $data['value'] = json_encode($this->input->post('values'));
            $this->db->where('key', 'courses');
            $this->db->update('frontend_settings', $data);
        }

I need to save these values via codeigniter in json format, like this:

["1","2","3"]

The function I created is not saving as I need it.

1 Answer 1

1

To make values array, add [] to name attribute:

<input type="text" value="1" name="values[]">
<input type="text" value="2" name="values[]">

With such naming $this->input->post('values') will be an array and will be correctly encoded to json.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.