Have an account? Sign in
Login  Register  Facebook
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">&nbsp;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
Started: November 20, 2011 Latest Activity: November 21, 2011 php js
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
In: November 21, 2011

The function provided does not work.Is their an alternative??
November 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer