Skip to content

Instantly share code, notes, and snippets.

@jawinn
Created December 17, 2013 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawinn/8012422 to your computer and use it in GitHub Desktop.
Save jawinn/8012422 to your computer and use it in GitHub Desktop.
CodeIgniter - Check username exists
//---------------------------------
// EMAIL EXISTS (true or false)
//---------------------------------
private function email_exists($email)
{
$this->db->where('email', $email);
$query = $this->db->get('users');
if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
}
//---------------------------------
// AJAX REQUEST, IF EMAIL EXISTS
//---------------------------------
function register_email_exists()
{
if (array_key_exists('email',$_POST)) {
if ( $this->email_exists($this->input->post('email')) == TRUE ) {
echo json_encode(FALSE);
} else {
echo json_encode(TRUE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment