尝试使用 codeigniter 将表单值插入数据库,但没有任何反应。我的表单是comment_form.php就像,
<?php echo validation_errors(); ?>
<?php echo form_open('news/comment_form'); ?>
Name<input type="text" name="comment_name"></input><br />
Email<input type="text" name="comment_email"></input><br />
Comment<input type="text" name="comment_body"></input><br />
<input type="submit" name="submit" value="Comment it" ></input>
</form>
这是我的控制器comments.php
class Comments extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('comment_model');
}
public function create_comment()
{
$this->load->helper('form');
$this->load->library('form_validation');
//$data['title'] = 'Create a news item';
$this->form_validation->set_rules('comment_name', 'comment_name', 'required');
$this->form_validation->set_rules('comment_email', 'comment_email', 'required');
$this->form_validation->set_rules('comment_body', 'comment_body', 'required');
if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header', $data);
$this->load->view('news/comment_form');
$this->load->view('templates/footer');
} else {
$this->news_model->set_comment();
$this->load->view('news/success');
}
}
}
这是我的模型comment_model.php
class Comment_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
public function set_comment()
{
//$this->load->helper('url');
//$slug = url_title($this->input->post('title'), 'dash', TRUE);
$datac = array(
'comment_name' => $this->input->post('comment_name'),
'comment_email' => $this->input->post('comment_email'),
'comment_body' => $this->input->post('comment_body')
);
return $this->db->insert('comments', $datac);
}
}
问题是每当我提交表单时它什么都不返回,就像什么都没发生一样。请帮忙。