Verify that email already exists with codeigniter

1

I want to check if an email already exists in the database. I'm doing the following.

$this->load->database();
      $query = $this->db->get_where('usuario', array('email'));
      $result = $query->result_array();
      if(count($result) > 0) {
        echo "email existe";

      } else { echo "email não existe";}

It always returns me that the email already exists even if I type a different one. Where is my mistake? Or am I doing wrong and have another way?

    
asked by anonymous 30.06.2016 / 14:22

1 answer

2

I thought of the following solution:

$this->db->select('email');
$this->db->where('email', $this->input->post('email'));
$retorno = $this->db->get('usuario')->num_rows();

if($retorno > 0 ){
    echo "este e-mail já está cadastrado";
} else { 
    echo "este e-mail está disponível";
}
    
30.06.2016 / 14:56