我正在尝试更新数据库并立即更改所有行,这是我正在使用的模型:
function amend_job($title,$description,$location,$date,$time,$pay,$jobcat,$job_id) //This function amends a job.//
{
$amendJob=array(
"JobTitle"=>$title,
"JobDescription"=>$description,
"JobLocation"=>$location,
"JobDate"=>$date,
"JobStartTime" =>$time,
"JobPay"=>$pay,
"JobCategory"=>$jobcat
);
$this->db->where('JobID', $job_id);
return $this->db->update('HM_Jobs', $amendJob);
}
代码运行时没有数据库或语法错误,我认为更新语法可能有误,有什么建议吗?
我已经更新了上面的功能,这里是控制器功能:
function amend_job()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('title','Title','required|trim|max_length[50]|xss_clean|strip_tags');
$this->form_validation->set_rules('description','Description','required|trim|max_length[200]|xss_clean|strip_tags');
$this->form_validation->set_rules('location','Location','required|trim|max_length[50]|xss_clean|strip_tags');
$this->form_validation->set_rules('date','Start Date','required|trim|max_length[20]|xss_clean');
$this->form_validation->set_rules('time','Time','required|trim|max_length[20]|xss_clean');
$this->form_validation->set_rules('pay','Pay Rate','required|trim|max_length[10]|xss_clean|number');
$this->form_validation->set_rules('jobcat','Job Category','required|trim|max_length[30]|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$data['usertype'] = $session_data['usertype'];
$data['id'] = $session_data['id'];
$this->load->view('amend_job_view', $data);
return false;
}
else{
//Sending form input.//
$title=$this->input->post('title');
$description=$this->input->post('description');
$location=$this->input->post('location');
$date=$this->input->post('date');
$time=$this->input->post('time');
$pay=$this->input->post('pay');
$jobcat=$this->input->post('jobcat');
//Sending session data.//
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$data['usertype'] = $session_data['usertype'];
$data['id'] = $session_data['id'];
$job_id=$this->uri->segment(3);
$this->load->model("job_model");
if($this->job_model->amend_job($title,$description,$location,$date,$time,$pay,$jobcat,$job_id))
{
echo $this->db->last_query();
/*Start of the PHP generated JavaScript that shows the details the user registered with.
echo "<script language=\"javascript\" type=\"text/javascript\">\n";
echo "alert('That job has been successfully amended, returning to your home.');\n";
echo " window.location.href='(my link)'; </script>";
End of the PHP generated JavaScript that shows the details the user registered with.*/
}
else
{
$data['msg']="An error was encountered when trying to add this job.";
}
}
$this->load->view("customer_view",$data);
}
现在找不到$ job_id,查询是:
UPDATE `HM_Jobs` SET `JobTitle` = 'dfsdsf', `JobDescription` = 'fd', `JobLocation` = 'fds', `JobDate` = '2014-01-01', `JobStartTime` = '02:00:00', `JobPay` = '32.00', `JobCategory` = 'Carpentry/Woodwork' WHERE `JobID` = 0
我正在使用uri段,链接如下: (我的网站)/HandyMan/index.php/job_controller/amend_page/43
答案 0 :(得分:1)
你在函数$job_id
和$id
中得到两个id。并且您没有在任何地方使用$id
。我想你应该再次检查参数并再次检查调用功能。可能是你正在混合这两个$ ID。
答案 1 :(得分:-2)
数组中有一个额外的逗号
$amendJob=array(
"JobTitle"=>$title,
"JobDescription"=>$description,
"JobLocation"=>$location,
"JobDate"=>$date,
"JobStartTime" =>$time,
"JobPay"=>$pay,
"JobCategory"=>$jobcat,
^
);
删除它并将数组更改为
$amendJob=array(
"JobTitle"=>$title,
"JobDescription"=>$description,
"JobLocation"=>$location,
"JobDate"=>$date,
"JobStartTime" =>$time,
"JobPay"=>$pay,
"JobCategory"=>$jobcat
);
并确保数组$amendJob
中的键是表的字段名。