CodeIgniter Forums
DB insert error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: DB insert error (/showthread.php?tid=3489)



DB insert error - El Forum - 10-05-2007

[eluser]feri_soft[/eluser]
I have the following simple code:

Code:
$data1 = array(
                    'product_id' => $product_id,
                      'image' => $img,
                    'thumb' => $thumb,
                    'order' => $i);  
                    $this->db->insert('images', $data1);

which is put in a loop and $i is the number. But when i run it it produces:

Quote: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 'order) VALUES ('95', '95_0.jpg', '95_0_thumb.jpg', 0)' at line 1

INSERT INTO images (product_id, image, thumb, order) VALUES ('95', '95_0.jpg', '95_0_thumb.jpg', 0)

Why is that? I can run other insert queries on the server but why this one fails as all seems to be normal. BTW i also tried putting unset($data1) at the end of the loop but its not helping. Thanks!


DB insert error - El Forum - 10-05-2007

[eluser]abmcr[/eluser]
order is a reserved word of MYSQl, i think... try edit tha name of the field as myorder... ciao


DB insert error - El Forum - 10-05-2007

[eluser]feri_soft[/eluser]
Ok i will give it a try however if no error is displayed on phpmyadmin when creating why now there is ?


DB insert error - El Forum - 10-05-2007

[eluser]bijon[/eluser]
When you create in phpMyadmin then the sql create like this way
Quote:INSERT INTO `test` ( `product_id` , `image` , `thumb` , `order` )VALUES ('1', 'ewre.jpg', 'test.jpg', 0');

But when you run through the active record then sql build
Quote:INSERT INTO test (product_id , image ,thumb ,ORDER )VALUES ('1', 'ewre.jpg', 'test.jpg', '0')
. Here order behaves likes the reserved key. That's why you get the sql error.

Check the Mysql Reserved words

So i also think to change the order name .

Thanks
Saidur