codeigniter和mysql更新错误?

when i try to update a table i get an error that time. error image

there is my controller code.

$this->hr_user->insert_user($info);

        $n=explode('--', $info['user_code']);
        $temp=$n[1];
        $lnum=ltrim($temp,'0');
        //print_r($lnum);
        //echo "<br>lastnumber".$lnum;
        $id=$info['user_type'];
        echo $id.''.$lnum;



        $this->hr_user->update_number($id,$lnum);



        redirect('hrm/index');

and here is my model code.

public function update_number($id,$lnum)
{
    $this->db->where('em_id',$id);
    $this->db->update('tbl_emaster.em_lastnumber',$lnum);

}
dongzhuo2010
dongzhuo2010 你试过这些答案吗?
大约 3 年之前 回复

4个回答

The mysql error you got explains every thing. Your query order doesn't generate a qualified query, try:

public function update_number($id,$lnum)
{
    $this->db->set('eenter code herem_lastnumber', '$lnum');
    $this->db->where('em_id',$id);
    $this->db->update('emaster');
}

for more info www.codeigniter.com

change query

public function update_number($id,$lnum)
{
    $data=array('em_lastnumber'=>$lnum);
    $this->db->where('em_id',$id);
    $this->db->update('tbl_emaster',$data);

}

Mysql update query syntax is :

UPDATE table_name SET field1 = new-value1, field2 = new-value2
[WHERE Clause]

You can see, there are fields after SET. And because of your CI update syntax, column name is not being passed. And to pass that, you should pass array as 2nd argument of $this->db->update('tbl_emaster.em_lastnumber',$lnum);

So you need to change it like this:

$this->db->update('tbl_emaster',array('em_lastnumber' => $lnum);
dongzhu7329
dongzhu7329 别客气。 乐于帮助。
大约 3 年之前 回复
dongzhina7098
dongzhina7098 谢谢,这是有效的。
大约 3 年之前 回复
$this->db->set('field', 'field+1');
$this->db->where('id', 2);
$this->db->update('mytable'); 
// gives UPDATE `mytable` SET `field` = '   field+1' WHERE `id` = 2

https://www.codeigniter.com/userguide3/database/query_builder.html#updating-data

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐