Zemanor Zemanor - 4 months ago 7
Javascript Question

Ajax signup issue

I'm trying to correct a login/sign up issue i'm having, and having trouble. I've included a jsfiddle with the code, but im not sure what I'm missing.


I am consistently able to insert users into the correct db table on submit, but it gives the "You have already created an account!" alert and inserts the info, even if the account is not in the table pre-submit. I want to reject the account if there is one in the database, or accept it if it doesn't currently exist. How do I correct this problem? (php incl in jsfiddle)

//signup js

var url="http://localhost/auth.php";


var fullname=$("#fullname").val();
var email=$("#email").val();
var password=$("#password").val();
var dataString="fullname="+fullname+"&email="+email+"&password="+password+"&signup=";

if($.trim(fullname).length>0 & $.trim(email).length>0 & $.trim(password).length>0)
type: "POST",
url: url,
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function(){ $("#signup").val('Connecting...');},
success: function(data){
alert("Thank you for registering with us! you can login now");
else if(data="exist")
alert("You already created an account!");
else if(data="failed")
alert("Something Went wrong");
}return false;



Use double == to compare

          else if(data=="exist")
                alert("You already created an account!");
            else if(data=="failed")

Also use double && in if to check multiple and condition.

Check this for more detail : http://www.w3schools.com/js/js_comparisons.asp