Duplicate Email Check
Hello,
I want to check the duplicate email but my code does not work. My Duplicate email check file is called - Emaildup.php <?php class User extends Application { private $_table = "clients"; public $_id; public function Emailduplicate($email = null) { if (!empty($email)) { $sql = "SELECT `id` FROM `{$this->_table}` WHERE `email` = '".$this->db->escape($email)."'"; return $this->db->fetchOne($sql); } echo '1';//If there is a record match in the Database - Not Available } else { echo '0';//No Record Found - Username is available } }The js code to check this is called - email.js $(document).ready(function()//When the dom is ready { $("#email").change(function() { //if theres a change in the email textbox var email = $("#email").val();//Get the value in the email textbox if(email.length > 3)//if the length greater than 3 characters { $("#availability_status").html('<img src="../images/loader.gif" align="absmiddle"> Checking availability...'); //Add a loading image in the span id="availability_status" $.ajax({ //Make the Ajax Request type: "POST", url: "../classes/Emaildup.php", //file name data: "email="+ email, //data success: function(server_response){ $("#availability_status").ajaxComplete(function(event, request){ if(server_response == '0')//if ajax_check_email.php return value "0" { $("#availability_status").html('<img src="../images/available.png" align="absmiddle"> <font color="Green"> Available </font> '); //add this image to the span with id "availability_status" } else if(server_response == '1')//if it returns "1" { $("#availability_status").html('<img src="../images/not_available.png" align="absmiddle"> <font color="red">Not Available </font>'); } }); } }); I think the problem is with the PHP code to check the record. Any help is much appreciated. Thank you
1 Answer
replace "Emailduplicate" function to:
public function Emailduplicate($email = null) { $sql = "SELECT `id` FROM `{$this->_table}` WHERE `email` = '".$this->db->escape($email)."'"; if ($this->db->fetchOne($sql)) { exit('1'); } else { exit('0'); } } Posted: MacOS 0 of 1 people found this answer helpful. Did you? Yes No The function provided does not work.Is their an alternative?? |
© Advanced Web Core. All rights reserved