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.

zecaluis
  • 145
  • 1
  • 9

1 Answers1

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.

u_mulder
  • 54,101
  • 5
  • 48
  • 64