我使用的是最新版本的codeigniter,但我遇到了问题。每当我提交包含必要详细信息的数据时,都不会发生数据库插入,form_validation->run() == FALSE
总是返回false,就像提交的数据存在问题一样。
这是我的代码:
class Auth extends CI_Controller {
public function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->database();
$this->load->model('user_model'); //database inserter
}
public function submit_join(){
$this->form_validation->set_rules('username', 'Username', 'is_unique[students.username]');
$this->form_validation->set_rules('email', 'Email', 'valid_email|is_unique[students.email]');
$this->form_validation->set_rules('phone', 'Mobile No.', 'numeric');
$this->form_validation->set_rules('password', 'Password', 'min_length[4]|max_length[20]|matches[confirm_pass]|md5');
$this->form_validation->set_rules('confirm_pass', 'Confirm Password', 'matches[password]|md5');
if ($this->form_validation->run() == FALSE)
{
// fails
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There was an error when verifying your details!</div>');
$this->load->view('join');
}
else
{
//insert the user registration details into database
$data = array(
'full_name' => $this->input->post('full_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'address' => $this->input->post('address'),
'sex' => $this->input->post('sex'),
'state' => $this->input->post('state'),
'phone' => $this->input->post('phone')
);
//Insert to database function
}
}
答案 0 :(得分:1)
您是否加载了表单验证库?它不在您的构造函数或函数中,因此这可以解决问题。
#include <vector>
#include <iostream>
int main(){
std::vector<int> vec;
#pragma omp declare reduction (merge : std::vector<int> : omp_out.insert(omp_out.end(), omp_in.begin(), omp_in.end()))
#pragma omp parallel for default(none) schedule(static) reduction(merge: vec)
for(int i=0;i<100;i++)
vec.push_back(i);
for(const auto x: vec)
std::cout<<x<<"\n";
return 0;
}
答案 1 :(得分:0)
首先检查所有字段名称是否与您在验证规则中设置的相同,而不是检查is_unique[students.email]
是否是连接数据库中的有效字段,如果一切正常则您的学生数据库包含电子邮件字段尝试在控制器中正确加载表单验证库,
删除确认密码规则中的md5。 将表单验证错误设置为视图中的表单,如
<?php echo form_error('name');?>
发现错误