验证后将数据放入数据库的更好方法是什么?我举两个例子:
第一
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Impossible to go on', 'required|xss_clean');
if ($this->form_validation->run() != FALSE) { // check the field validation
$username = $this->input->post('username'); // fist way
$this->model_db->insert_username($username);
}
第二
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Impossible to go on', 'required|xss_clean');
if ($this->form_validation->run() != FALSE) { // check the field validation
$username = $this->form_validation->set_value('login'); // second way
$this->model_db->insert_username($username);
}
答案 0 :(得分:3)
我认为第一个是有效的方式,因为在
之内if ($this->form_validation->run() != FALSE) { }
表示验证正常,即用户名字段不为空白,现在您可以获取用户名并将其插入数据库。