0

I'm validating user email by ajax and php but here ajax always showing email already exit;

AJAX/Javascript Code:

$.ajax({
    type: "POST",
    url: "classes/aeAjaxFunction.php",
    data: "do=sem&ci=" + ci11,
    success: function(msg) {
        if(msg ="yes") {
            alert('Email already exist');
        }
        else {
        // alert("Occured internal Error. please check network connection");
        }

        // $('#psid').html("<img src='images/spacer.gif'>");

        //$('#email1').html(msg);

        //

        //$('#sid').sSelect({ddMaxHeight: '300px'});

    },
    error: function() {
        // alert('some error has occured...');
    },
    start: function() {
        // alert('ajax has been started...');   
    }
});

PHP Code:

<?php

function checkSpEmail($postAr) {

    $mysqli = dbconn::get_mysqli();
    $email = $postAr['ci'];

    $selEmail = "SELECT fld_email FROM tbl_spouse WHERE fld_email = '$email' ";

    $res = mysqli_query($mysqli, $selEmail);
    $count = mysqli_num_rows($res);

    if (mysqli_num_rows($res) == 1) {
        echo 'yes';
        exit;
    }
}

?>
user1978142
  • 7,946
  • 3
  • 17
  • 20
user3546207
  • 20
  • 1
  • 3
  • 1
    i dont know if this is a typo but you should change this on your code: `if(msg ="yes") {` to `if(msg == "yes") {` – user1978142 Apr 23 '14 at 05:20

2 Answers2

0

change your ajax code, you are using msg = "yes" and you must have to use msg == "yes"

$.ajax({
    type: "POST",
    cache: false, 
    url: "classes/aeAjaxFunction.php",
    data: "do=sem&ci=" + ci11,
    success: function(msg) {
        if(msg == "yes") {
            alert('Email already exist');
        }
        else {
        // alert("Occured internal Error. please check network connection");
        }

        // $('#psid').html("<img src='images/spacer.gif'>");

        //$('#email1').html(msg);

        //

        //$('#sid').sSelect({ddMaxHeight: '300px'});

    },
    error: function() {
        // alert('some error has occured...');
    },
    start: function() {
        // alert('ajax has been started...');   
    }
});
Zeeshan
  • 1,659
  • 13
  • 17
  • how to do cache false of ajax – user3546207 Apr 23 '14 at 06:01
  • I have updated my code with cache false, you can also see this for cache false. http://stackoverflow.com/questions/4303829/how-to-prevent-a-jquery-ajax-request-from-caching-in-internet-explorer – Zeeshan Apr 23 '14 at 06:06
0

Change

if(msg ="yes") 

to

if(msg =="yes")
Roy M J
  • 6,926
  • 7
  • 51
  • 78