验证之后将数据放到数据库中的更好方法是什么?我给你2个例子:
第一的
$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);
}
我认为第一个是有效的方法,因为
if ($this->form_validation->run() != FALSE) { }
表示可以通过验证,即用户名字段不为空,现在您可以获取用户名并将其插入数据库。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句