【发布时间】:2019-06-17 03:56:26
【问题描述】:
如何传递post中的数据以便我们调用id?
因为我们正在尝试获取问题的“qtopic_id”,但它不起作用,并且它一直给我一个空值。
我已尝试声明 qtopic_id= 19 以查看其是否保存在 qtopic_id 列中。 我不必将特定的 id 值保存在以下列中,这样它就不会仅保存在该特定 id 上,而是会保存在其相应的 qtopic_id 上。
控制器
public function addChoices(){
$this->form_validation->set_rules('ques','Question','required');
$this->form_validation->set_rules('ch_des1','Choices','required');
$this->form_validation->set_rules('ch_des2','Choices','required');
$this->form_validation->set_rules('ch_des3','Choices','required');
$this->form_validation->set_rules('ch_des4','Choices','required');
$this->form_validation->set_rules('ans','Answer','required');
$this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
if($this->form_validation->run() ){
echo $qtopic_id ;
$data['ques'] = ($this->input->post('ques'));
$data['ch_des1'] = ($this->input->post('ch_des1'));
$data['ch_des2'] = ($this->input->post('ch_des2'));
$data['ch_des3'] = ($this->input->post('ch_des3'));
$data['ch_des4'] = ($this->input->post('ch_des4'));
$data['ans'] = ($this->input->post('ans'));
if($id=$this->queries->registerChoices($data) )
{
$this->session->set_flashdata('message','Test Added Succesfully');
return redirect('admin/testtwo');
}
else {
$this->session->set_flashdata('message','Failed to Add Test');
}
return redirect('admin/testtwo');
}
else {
$this->addQuestion();
}
}
}
型号:
----更新---
public function registerChoices($data) {
echo $this->input->post('qtopic_id');
$question_arr = [
'ques' => $data['ques'],
'qtopic_id' => 19
];
$choices_arr = [
'ques' => $data['ques'],
'ch_des1' => $data['ch_des1'],
'ch_des2' => $data['ch_des2'],
'ch_des3' => $data['ch_des3'],
'ch_des4' => $data['ch_des4'],
'ans' => $data['ans']
];
// echo "<pre>";
// var_dump($question_arr);
// var_dump($choices_arr);
// exit;
$this->db->insert('tbl_choices',$choices_arr);
$this->db->insert('tbl_question',$question_arr);
return $this->db->insert_id();
}
【问题讨论】:
-
model 或 addchoices 中显示的 null 错误在哪里,您尝试从哪里发布 qtopic_id 。在你注册选择的模型中,你试图打印 qtopic_id 但你没有从控制器发送参数 qtopic_id,并且你再次尝试在模型中设置 qtopic_id 值,它有点混淆你想要什么
-
您的问题还不清楚,请在此处添加更多代码和更多说明
-
我已经包含了错误并添加了一些额外的代码..谢谢你!!
标签: php codeigniter