Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在验证用户和未验证用户_Php_Codeigniter - Fatal编程技术网

Php 正在验证用户和未验证用户

Php 正在验证用户和未验证用户,php,codeigniter,Php,Codeigniter,我正在尝试验证用户名的输入字段。我创建了一个回调函数来报告用户输入是否已经作为名称存在于数据库中,但每次它都报告它确实存在。即使数据库里什么都没有。对save函数的调用来自jqueryajax请求 public function save() { $output_status = 'Error'; $output_title = 'Not processed'; $output_message = 'The request was unprocessed!';

我正在尝试验证用户名的输入字段。我创建了一个回调函数来报告用户输入是否已经作为名称存在于数据库中,但每次它都报告它确实存在。即使数据库里什么都没有。对save函数的调用来自jqueryajax请求

public function save()
{
    $output_status = 'Error';
    $output_title = 'Not processed';
    $output_message = 'The request was unprocessed!';

    $this->form_validation->set_rules('username', 'User Name', 'required|trim|xss_clean|callback_username_check');

    if ($this->form_validation->run())
    {
        $user_saved = $this->users_model->save_user($this->input->post('username'), $this->input->post('user_directory_name'), $this->input->post('user_status'));
        if ($user_saved)
        {
            $output_status = 'Success';
            $output_title = 'User Created';
            $output_message = 'User was successfully created!';
        }
        else
        {
            $output_title = 'User Not Created';
            $output_message = 'User was not successfully created!';
        }
    }
    else
    {
        $output_title = 'Form Not Validated';
        $output_message = validation_errors();
    }
    echo json_encode(array('status' => $output_status, 'title' => $output_title, 'message' => $output_message));  
}

public function username_check($title_name)
{
    $username_exists = $this->users_model->get_user(array('username' =>$username));
    if (is_null($username_exists))
    {
        $this->form_validation->set_message('username_check', 'The username already exists!');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}  

这可能是因为回调函数使用了一个未定义的变量。 您应该将$username更改为$title\u name,或将visa更改为$title\u name

public function username_check($username)
{
  $username_exists = $this->users_model->get_user(array('username' =>$username));
  if (is_null($username_exists))
  {
    $this->form_validation->set_message('username_check', 'The username already exists!');
    return FALSE;
  }
  else
  {
    return TRUE;
  }
}  
您可以从规则中执行此操作: $this->form_validation->set_rules('username','username','required |是唯一的[users.username])