Welcome Guest, Not a member yet? Register   Sign In
Insert db and Error Number: 1054
#1

[eluser]zimco[/eluser]
I've seen other threads in the forum related to this error and cannot discern if it is: a CI bug, or according to some other threads i'm trying to do something using active records insert that i'm not allowed to do and by reading the user's manual i should see what it is i have done wrong. However, i'm not seeing it. So how can i do a simple insert of an array of values into my database?

In my controller i have done this
Code:
$event=array();
$event=$data['conditions'];
$this->insert_event($event);
the function insert_event
Code:
function insert_event($event) {
  $this->load->database();
        print_r($event);
        $this->db->insert('race_events', $event);
    }

Which results in this:
Array ( [0] => 15 [1] => 03/26/1998 [2] => RACE TRACK [3] => $ 500 [4] => NW12501L6 [5] => SLOW [6] => Evening [7] => 1 Mile [8] => FT [9] => 56.0 [10] => 9 )

An Error Was Encountered

Error Number: 1054

Unknown column '0' in 'field list'

INSERT INTO `race_events` (`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`) VALUES ('15', ' 03/26/1998 ', ' RACE TRACK ', '$ 500', 'NW12501L6', 'SLOW', ' Evening ', '1 Mile', 'FT', '56.0 ', '9')
#2

[eluser]kgill[/eluser]
The obvious thing that stands out is your insert statement, I don't think you named your table columns, 0, 1, 2, 3, etc. instead they probably have useful names like race_date, winnings and so on. Those values need to be in your array so that when it is passed to the db->insert function it sees $event['race_date'] = ‘ 03/26/1998 ‘ not $event[1] = ‘ 03/26/1998 ‘

- K
#3

[eluser]zimco[/eluser]
OK, that makes sense. Please excuse my DUH moment.




Theme © iAndrew 2016 - Forum software by © MyBB