1

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?

2
  • Here you need to change Image Sensor to ImageSensor or some thing else in to your $spec_array. Commented Nov 30, 2016 at 7:16
  • @MayankVadiya thanks... i used this function str_replace(' ','",$specification); So that if there will be any space it will be replaced by '' .. so that it will not cause any trouble in future... :) Commented Nov 30, 2016 at 12:21

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I think you have error here:

`Image` `Sensor` = 'sklfj',

After image you didn't give the value to it.

2 Comments

Actually Image Sensor is only one property... it defines whether camera contains image sensor or not.... Can we use Space in key names??
so use the backtick correctly ImageSensor like this
1

Since Image Sensor is a column with space in it, therefore you are getting an error. CI is adding ` to every field with a space. It is not a good practice to use a space in your columns in MySQL.

In order to solve this problem, either you should remove space or write a query in below mentioned form and pass it in $this->db->query().

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'

1 Comment

Ohh... Got that.. I changed every table containing space and replaced it with '_' ... Thanks.. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.