Check if a user registered with the bank has already registered cpf

Hello, guys I'm needing to check in the bank if a logged in user already has registered cpf and return if it is false or not.

I use codeigniter in the application. I'll send the codes. CONTROLLER:

public function check_cpf_doctor() { 
$check_result = $this->Doctor_model->checkCPFDoctor($_POST['doctor_id']);
  print json_encode($check_result);
}

/ / DOCTOR_MODEL

public function checkCPFDoctor($id)
{
    $key = $this->config->item('encryption_key');

    $query = 

    if($query['crm'])

    {
        return true;
    }
    else
    {
        return false;
    }


}

This model query is wrong and incomplete because I could not finish, I want to return the data of the user who is logged in.

Author: jona1has, 2018-12-01

2 answers

Using form_validation in your Controller it is possible to validate if a value is unique, informing the table and searched value:

$this->form_validation->set_rules('cpf', 'Cpf', 'required|is_unique[doctors.cpf]');

To catch the errors just use the call validation_errors();

Note: exchange doctors for the name of your table, if this is not its name.

Https://www.codeigniter.com/userguide3/libraries/form_validation.html

 1
Author: edson alves, 2018-12-03 15:48:22

You can do as follows:

// Controller
public function check_cpf_doctor() { 
    $check_result = $this->Doctor_model->checkCPFDoctor($this->input->post('doctor_id'));
    if($check_result==1){
        echo "Este CPF já está cadastrado";
    } else {
        echo "CPF não cadastrado";
    }
}

// Model
public function checkCPFDoctor(){
    $this->db->where('cpf', $this->input->post('doctor_id'));
    $check = $this->db->get('table')->num_rows();
    return $check;
}

In this case, we return with num_rows (), in case of Return 1, it is already registered, if not, it is not registered.

 0
Author: Sr. André Baill, 2018-12-02 21:36:08