Welcome Guest, Not a member yet? Register   Sign In
Insert array into database
#1

[eluser]bohara[/eluser]
Hi,
I am trying to insert a array into my database. I had this working and I am not sure why it broke.

In my model I have this:
Code:
$reminder_id = $row['id'];
        
        for ($i = 0; $i <= count($_POST['bulb_type_id'])-1; $i++) {
            
                $sql = array(
                $this->reminder_id = $reminder_id,
                $this->quantity = $_POST['quantity'][$i][1],
                $this->bulb_type_id = $_POST['bulb_type_id'][$i][2],
                $this->shatterproof = $_POST['shatterproof'][$i][3],
                );
        
        }

$this->db->insert('line_items', $sql);

The array part of my form look like this: on the interface you can add more rows through AJAX that increment the the form values like [1][1], [1][2], [1][3], and so on.
Code:
<tbody id="container">
            <tr id="row0">
                <td>    
                    &lt;input type="text" name="quantity[0][1]" value="" maxlength="2" size="2"  /&gt;
                </td>
                <td>    
                    &lt;? echo form_dropdown('bulb_type_id[0][2]', $bulb_types); ?&gt;
                </td>
                <td>    
                    &lt;? echo form_checkbox('shatterproof[0][3]', 1, false); ?&gt;
                </td>
            </tr>
        </tbody>

I recieve the following errors:

----------------------------------------
A PHP Error was encountered

Severity: Notice

Message: Undefined index: shatterproof

Filename: models/reminder_model.php

Line Number: 67

----------------------------------------

An Error Was Encountered
Error Number: 1054

Unknown column '0' in 'field list'

INSERT INTO `line_items` (`0`, `1`, `2`, `3`) VALUES ('50', '1', '2', NULL)

-----------------------------------------

I hope this is enough information. Thanks in advance


Messages In This Thread
Insert array into database - by El Forum - 07-23-2008, 12:38 PM
Insert array into database - by El Forum - 07-24-2008, 08:30 AM
Insert array into database - by El Forum - 07-24-2008, 10:08 AM
Insert array into database - by El Forum - 07-24-2008, 10:25 AM
Insert array into database - by El Forum - 07-24-2008, 10:34 AM
Insert array into database - by El Forum - 07-24-2008, 10:38 AM
Insert array into database - by El Forum - 07-24-2008, 10:41 AM
Insert array into database - by El Forum - 07-24-2008, 10:43 AM
Insert array into database - by El Forum - 07-24-2008, 10:48 AM
Insert array into database - by El Forum - 07-24-2008, 11:00 AM
Insert array into database - by El Forum - 07-24-2008, 11:49 AM
Insert array into database - by El Forum - 07-24-2008, 12:04 PM
Insert array into database - by El Forum - 07-24-2008, 12:09 PM
Insert array into database - by El Forum - 07-24-2008, 01:44 PM
Insert array into database - by El Forum - 08-26-2008, 12:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB