I am trying to check whether the user email exists or not in CodeIgniter.
Here is the controller of CodeIgniter which I am using:
public function check_email() {
$email= $this->input->post('email');
echo "error";
if($email)
{
$this->load->model('auth/register_model');
$return_array = $this->register_model->check_member($this->input->post('email'));
if($return_array == true)
{
$json['success'] = 'false' ;
$json['exit'] = 'true';
die(json_encode($json,JSON_PRETTY_PRINT));
}
else
{
$json['success'] = 'true' ;
$json['exit'] = 'false';
die(json_encode($json,JSON_PRETTY_PRINT));
}
}
}
Here is the model of CodeIgniter which I am using:
public function check_member($email) {
$this->db->select('user_id')->from(DB_PREFIX .'publisher')->where('email', $email);
$q = $this->db->get();
if ($q->num_rows() == 1) {
return true;
}
return false;
}
Here is the AJAX of CodeIgniter which I am using:
function checkAvailability() {
if($("#email").val()) {
$(".showLiveEmail").addClass("fa fa-refresh fa-spin");
$(".showEmail").removeClass("has-success");
jQuery.ajax({
url: "auth/register/check_email",
data:'email='+$("#email").val(),
type: "POST",
success:function(data){
if(data.success=="true")
{
$(".showLiveEmail").removeClass("fa fa-refresh fa-spin");
$(".showEmail").removeClass("has-error")
$(".showLiveEmail").removeClass("fa fa-times");
$(".showLiveEmail").addClass("fa fa-check");
$(".showEmail").addClass("has-success");
}
else
{
}
},
error:function (){}
});
}
else
{
$(".showLiveEmail").addClass("fa fa-times");
$(".showEmail").removeClass("has-success")
$(".showEmail").addClass("has-error")
}
}
Can anyone please help me out? I just started CodeIgniter and I'm now facing this.