Welcome Guest, Not a member yet? Register   Sign In
DB insert error
#1

[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!
#2

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

[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 ?
#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB