错误 视图中的“提交”按钮不会传递值。
单击提交按钮后,将值从视图传递到控制器,然后传递给模型。数据库结构由表(预订)和列名(scheduled_id,名称和移动)组成。但是该值不会传递给控制器也不会传递给数据库。
查看
<form method="post" action="">
<input type="text" value="<?php echo isset($post)?$post->name:''; ?>" name="manakamana[name]"/>
<input type="text" value="<?php echo isset($post)?$post->mobile:''; ?>" name="manakamana[mobile]"/>
<button type="submit" class="btn btn-success">POST</button>
</form>
控制器
public function bookManakamana(){
if ($data = $this->input->post('manakamana')) {
$data['created_on'] = date('Y-m-d H:i:s');
$this->booking->add($data);
redirect('booking');
} else {
$this->load->view('index');
}
}
模型
function add($data)
{
$this->db->insert('booking', $data);
}
答案 0 :(得分:0)
未给出表格行动
<form method="post" action="<?php echo base_url().'controller name/function name' ?>">
<input type="text" value="<?php echo isset($post)?$post->name:''; ?>" name="name"/>
<input type="text" value="<?php echo isset($post)?$post->mobile:''; ?>" name="mobile"/>
<button type="submit" class="btn btn-success">POST</button>
控制器中的
public function bookManakamana(){
if ($this->input->post('name')) {
$data['created_on'] = date('Y-m-d H:i:s');
$data['name'] = $this->input->post('name');
$data['mobile'] = $this->input->post('mobile');
$this->booking_models->add($data); //booking_model is the name of model
redirect('booking');
} else {
$this->load->view('index');
}}