I want users to enter their email click a button and then check to see if the email is already in the database this is what i tried so far with no success
model
public function email_exists($email) {
$this->db->select('*');
$this->db->from('users');
$this->db->where('email', $email);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
Controller
function email_exists(){
$this->load->model('main_model');
$email = $this->input->post('email');
$exists = $this->main_model->email_exists($email);
$count = count($exists);
echo $count;
if (empty($count)) {
return true;
} else {
return false;
}
}
View Im adding the ajax code in the view im not sure if this is right
<input id="about-email" type="email">
<div id="about-you" >enter</div>
<script>
var email = $("#about-email").val();
$('#about-you').click(function() {
$.ajax({
type:"post",
url: "<?php echo base_url(); ?>index.php/my_controller_name/email_exists",
data:{ email:email},
success:function(response)
{
if (response == true) {
$('#msg').html('<span>email exists</span>');
} else {
$('#msg').html('<span>Value does not exist</span>');
}
}
});
});
</script>
The ajax code above breaks all my javascript for that page I'm also making a another ajax call on the same page so I don't know if it possible to make 2 ajax calls on one page.