ravi ravi - 3 days ago 5
MySQL Question

How to solve this error in MySql Query syntax in codeigniter?

This is The Error i am getting..

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 '`Sensor` = 'sklfj', `Lens` = 'lkjsdf', `IR` = 'lkjdsf', `Audio` = 'kjlasf', `WDR' at line 1

UPDATE `hdtvicameras_spec` SET `Resolution` = 'd', `Image` `Sensor` = 'sklfj', `Lens` = 'lkjsdf', `IR` = 'lkjdsf', `Audio` = 'kjlasf', `WDR` = 'lkjsf1', `ICR` = 'klasjf', `IP` `Rating` = 'lkjsdf', `Zoom` = 'ljs' WHERE `product_id` = '46'


Product_model.php

$this->db->where('product_id', $product_id);
$this->db->update($tbname, $spec_array);


After
var_dump($spec_array)
this is what i get

array(10) { ["Resolution"]=> string(5) "first" ["Image Sensor"]=> string(6) "second" ["Lens"]=> string(6) "third " ["IR"]=> string(6) "fourth" ["Audio"]=> string(6) "fifthe" ["WDR"]=> string(6) "sisxth" ["ICR"]=> string(5) "seven" ["IP Rating"]=> string(5) "eight" ["Zoom"]=> string(4) "nine" ["SD Card"]=> string(3) "ten" }


All those key values in array are fetched from database which is specification names of any product..

looks like there is some error with space in key name... can anybody help me solve this?

Answer

use query like this and check:

 UPDATE `hdtvicameras_spec` SET `Resolution` = 'd', `Image Sensor` = 'sklfj', `Lens` = 'lkjsdf', `IR` = 'lkjdsf', `Audio` = 'kjlasf', `WDR` = 'lkjsf1', `ICR` = 'klasjf', `IP Rating` = 'lkjsdf', `Zoom` = 'ljs' WHERE `product_id` = '46'

Since you added quotes, for fields names having more then 1 word, its showing error.

Comments