0
$colName = $this->input->post('colName'); $value = $this->input->post('value'); $jobId= $this->input->post('jobId'); $this->db->query("UPDATE test set ".$colName." = ".$value." where id= ".$jobId); 

I am able to update numeric values. However getting an error

Error Number: 1054

Unknown column '345drt' in 'field list'

UPDATE test set TTDNo1 = 345drt where id = 41

How can I update numeric, string & date fields in DB?

2
  • 2
    "UPDATE test set $colName = '$value' where id = '$jobId'" Commented Apr 18, 2016 at 6:14
  • col TTDNo1 has what datatype assigned in db, @VDS Commented Apr 18, 2016 at 6:32

4 Answers 4

1

Try this

$this->db->query("UPDATE test set ".$colName." = '".$value."' where id= ".$jobId); 
Sign up to request clarification or add additional context in comments.

16 Comments

it is updating in DB, however getting an error on browser as "The URI you submitted has disallowed characters."
I have previouly added "" before column name as it safe: "UPDATE test set ".$colName."` = '".$value."' where id= ".$jobId. Are you sure that your column name is "345drt"?
do you have field/column name "345drt"?
colName is "TTDNo1". Value is "345drt "
Echo your update query in browser & confirm that your value must be quoted I mean to say update query must be : UPDATE test set TTDNo1 = '345drt' where id = 41 or UPDATE test set TTDNo1 = '345drt' where id = 41 or UPDATE test set TTDNo1 = "345drt" where id = 41
|
0

Try like this:

$this->db->query("UPDATE test set ".$colName." = '".$value."' where id= ".$jobId); 

Comments

0

Unknown column '345drt' in 'field list'

it looks you have wrong value for column name, you put the value in the column name try to print the value of $colName and $value befor exute the query and do the query as @Dipanwita Kundu did

4 Comments

colName is "TTDNo1". Value is "345drt"
echo "UPDATE test set ".$colName." = ".$value." where id= ".$jobId; paste the result of this echo in comments here'
the query should be like this "UPDATE test set " . $colName . " = '" . $value . "' where id= " . $jobId; and the echo value is UPDATE test set TTDNo1 = '345drt' where id= 41
UPDATE test set TTDNo1 = '56ttt' where id = 41
0

Since the Column is varchar, you should try concatenating your variables :

$this->db->query("UPDATE test set ".$colName." = '".$value."' where id= '".$jobId."' "); 

1 Comment

@VDS, did the answer solved your issue. Please accept any answer that solved your issue. So will be helpful for other users as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.