更新时出现Mysql错误

时间:2016-08-25 10:12:08

标签: php mysql codeigniter web-applications codeigniter-2

错误看起来像这样:

  

'where子句'

中的未知列'resignation_id ='158''

UPDATE pr_temporary_absconding_checklists SET completion_status = 'pending' WHEREresignation_id='158' AND checklist_id='4'

我的型号代码是:

function submit_absconding_checklist($post_array, $idss) {

  $this->load->database();
  $ids = $this->uri->segment(4);
  $where = "resignation_id='$ids' AND checklist_id='$idss'";
  $this->db->where($where);
  $dbdata = array(
    "completion_status" => $post_array['completion_status']
  );

  $this->db->update('pr_temporary_absconding_checklists', $dbdata);
  print_r($query);
  die;
  /**
   * if required add this code here to check
   *
   * echo $this->db->last_query();
   */
  return 'Checklist updated successfully';
}

还附上了表格图片enter image description here

4 个答案:

答案 0 :(得分:1)

删除查询中resignation_id='158'周围的反引号。

它应该是这样的:

UPDATE `pr_temporary_absconding_checklists` SET `completion_status` = 'pending' WHERE `resignation_id`='158' AND `checklist_id`='4'

型号代码:

function submit_absconding_checklist($post_array, $idss) {

  $this->load->database();
  $ids = $this->uri->segment(4);
  $this->db->where('resignation_id', $ids); // UPDATED
  $this->db->where('checklist_id', $idss); // UPDATED
  $dbdata = array(
    "completion_status" => $post_array['completion_status']
  );

  $this->db->update('pr_temporary_absconding_checklists', $dbdata);
  print_r($query);
  die;
  /**
   * if required add this code here to check
   *
   * echo $this->db->last_query();
   */
  return 'Checklist updated successfully';
}

答案 1 :(得分:1)

您可以将活动记录格式的查询写为

$this->db->set("completion_statuscompletion_status", $post_array['completion_status']);
$this->db->where("resignation_id", $ids);
$this->db->where("checklist_id", $idss);
$this->db->update("pr_temporary_absconding_checklists");
$afftectedRows = $this->db->affected_rows();

答案 2 :(得分:0)

试试这个

$data = array(
    'completion_status' => $post_array['completion_status']
);

$this->db->where('resignation_id', $ids);
$this->db->where('checklist_id', $idss);
$this->db->update('mytable', $data);

答案 3 :(得分:0)

您应该尝试此代码。

function submit_absconding_checklist($post_array, $idss) {
    $this->load->database();
    $ids = $this->uri->segment(4);
    $dbdata["completion_status"] = $post_array['completion_status'];
    $this->db->update("pr_temporary_absconding_checklists", $dbdata, array('resignation_id' => $ids,'checklist_id'=>$idss));

    print_r($query);
    die;
    /**
      * if required add this code here to check
      *
      * echo $this->db->last_query();
    */
    return 'Checklist updated successfully';
  }