0

Following is code for calling ajax as well as php which is not working please help me. It gives 500 error i don't know why. I have also used $ instead of jQuery and jquery.min.js is also there.

jQuery.ajax({

        url: 'http://domain.com/adminer/validate.php',
        method    : 'post',
        data    : {email:emailField.value},
        dataType: 'text',
        success : function(data){
            if(data=="1")
            {
                alert('Already exists');
                return false;
            }
            else
            {
                alert('available');
                return false;
            }
        }
});             

Here is the php code to get email details and reruns the message 1.The php code is working fine but here is something misstate which will be gives 500 error which is display into console.

if($_POST['email'])
{       
        $con = mysqli_connect("localhost","uname","pass","dbname");
        if (mysqli_connect_errno())
        {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }       
        $result = mysqli_query($con,"SELECT email FROM master_user where email='".$_POST['email']."'");
        $row_cnt = $result->num_rows;
        if($row_cnt > 0){               
            echo "1"; exit;
        }
        else
        {
            echo "2"; exit;
        }
        mysqli_close($con);
} 
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
webseo
  • 5
  • 7

1 Answers1

0

Change your code as per below.I have not tested but ,I think its working fine.

jQuery.ajax({

    url: 'http://domain.com/adminer/validate.php?email='+emailField.value,
    method    : 'post',
    success : function(data){
        if(data=="1")
        {
            alert('Already exists');
            return false;
        }
        else
        {
            alert('available');
            return false;
        }
    }

});

T L Patel
  • 86
  • 5