CodeIgniter Forums
active record insert issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: active record insert issue (/showthread.php?tid=31546)



active record insert issue - El Forum - 06-23-2010

[eluser]Matrices[/eluser]
I'm trying to insert some info into a table. Here's my code:
Code:
$data = array(
        'client_id'    => $input['client_id'],
        'title'        => $input['title'],
        'slug'         => $input['slug'],
        'desc'         => $input['desc'],
        'date_create'  => now()
      );
  
$this->db->insert('proof_albums', $data);

and I'm receiving a MySQL error back:
Quote:A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, date_create) VALUES ('7', 'test', 'test-test', 'testest', 1277316812)' at line 1

INSERT INTO proof_albums (client_id, title, slug, desc, date_create) VALUES ('7', 'test', 'test-test', 'testest', 1277316812)

I'm not quite sure why this is. Can anyone point me in the right direction?


active record insert issue - El Forum - 06-23-2010

[eluser]Matrices[/eluser]
So I've run a few tests, and I know that it has something to do with 'desc' because the code runs fine if I take that line out.

In the database table, 'desc' is set as type 'text', with a collation of 'utf8_unicode_ci'. The $input array is receiving the value from a textarea via $_POST. There's nothing particularly special about the form though.

Still researching...


active record insert issue - El Forum - 06-23-2010

[eluser]Matrices[/eluser]
I guess the code didn't like my word choice of 'desc'. Once I changed that to 'description', it ran fine. Is there a reason for this? I'd like to know why if there is an answer, just so I'm the wiser in the future.


active record insert issue - El Forum - 06-23-2010

[eluser]WanWizard[/eluser]
Desc is reserved word.


active record insert issue - El Forum - 06-23-2010

[eluser]Matrices[/eluser]
Well that would do it, thanks! Smile