Basically, I made a login/register with PHP and Ajax to work with phonegap. The login works, if I try to create an account with the same email as an existing one, it responds, but when I try to create a new account, it says registration failed.~
Above there is the code

PHP code

```
<?php
$con = mysqli_connect("localhost","root","", "login") or die("connection error");
$email = $_POST['email'];
$password = $_POST['password'];

if(isset($_POST['register']))
{   
    $register = mysqli_num_rows(mysqli_query($con, "SELECT * FROM users WHERE email='$email'"));
    if($register == 0)
    {
        $insert = mysqli_query($con,"INSERT INTO users (email,password) VALUES ('$email','$password')");
        if($insert)                 
            echo "success";
        else
            echo "error";
    }
    else if($register != 0)
        echo "exist";
}
else if(isset($_POST['login']))
{
    $login = mysqli_num_rows(mysqli_query($con, "SELECT * FROM users WHERE email='$email' AND password`='$password'"));
    if($login != 0)
        echo "success";
    else
        echo "error";
}
mysqli_close($con);
?>

```

AJAX code
 // this is login code 

```
$("#loginButton").click(function(){
            var email= $.trim($("#email").val());
            var password= $.trim($("#password").val());

            $("#status").text("Authenticating...");
            var loginString ="email="+email+"&password="+password+"&login=";
            $.ajax({
                type: "POST",crossDomain: true, cache: false,
                url: url,
                data: loginString,
                success: function(data){
                    if(data == "success") {
                        $("#status").text("Login Success..!");
                        localStorage.loginstatus = "true";
                        window.location.href = "app.html";
                    }
                    else if(data == "error")
                    {
                        $("#status").text("Login Failed..!");
                    }
                }
            });
        });

   $("#registerButton").click(function(){
            var email= $.trim($("#email").val());
            var password= $.trim($("#password").val());

            $("#status").text("Creating New Account...");
            var dataString="email="+email+"&password="+password+"&register=";
            $.ajax({
                type: "POST",crossDomain: true, cache: false,
                url: url,
                data: dataString,
                success: function(data){
                    if( data == "success")
                        $("#status").text("Registered Success");
                    else if( data == "exist")
                        $("#status").text("Account is already there");
                    else if( data == "error")
                        $("#status").text("Register Failed");
                }
            });

```