0

I'm using phonegap and coding a simple registration page that uses a PHP/MYSQL method to insert. here is my code but it doesn't work!! all paths and codes seems true but it doesn't work and made me crazy :( what is the problem?

HTML & JS :

<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>JoinX</title>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#register").click(function() {
                var username = $("#username").val();
                var password = $("#password").val();
                var email = $("#email").val();
                var dataString = "username=" + username + "&password=" + password + "&email=" + email + "&insert=";
                if ($.trim(username).length > 0 & $.trim(password).length > 0 & $.trim(email).length > 0) {
                    $.ajax({
                        type: "POST",
                        url: "http://127.0.0.1/phonegap/insert.php",
                        data: dataString,
                        crossDomain: true,
                        cache: false,
                        beforeSend: function() {
                            $("#register").val('Connecting...');
                        },
                        success: function(data) {
                            if (data == "ok") {
                                alert("inserted");
                                $("#register").val('submit');
                            } else if (data == "error") {
                                alert("error");
                            }
                        }
                    });
                }
                return false;
            });
        });
    </script>
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <link rel="icon" href="icon.png">
    <link rel="stylesheet" href="themes/joinx.min.css" />
    <link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>

<body>
    <div data-role="page" data-theme="a" id="login">
        <div data-role="header" data-position="inline">
            <h1>Welcome</h1>
        </div>
        <div data-role="content" data-theme="a">
            <p align="center">Don't Have An Account? <a href="#signup" class="ui-link">Register Now!</a>.</p>
            <label for="slider1">Username :</label>
            <input type="text" name="username2" id="username2" data-theme="Login" />
            <label for="slider1">Password :</label>
            <input type="password" name="Password2" id="Password2" data-theme="Login" />
            <input type="submit" name="login" id="login" value="Login" data-theme="Login" />
        </div>
    </div>
    <div data-role="page" data-theme="a" id="signup">
        <div data-role="header" data-position="inline">
            <h1>Register A New Account</h1>
        </div>
        <div data-role="content" data-theme="a">
            <p align="center">Already Have An Account? <a href="#login" class="ui-link">Sign In Here!</a>.</p>
            <label for="slider1">Username :</label>
            <input type="text" name="username" id="username" data-theme="Login" />
            <label for="slider1">Password :</label>
            <input type="password" name="Password" id="Password" data-theme="Login" />
            <label for="slider1">Email Address :</label>
            <input type="email" name="email" id="email" data-theme="Login" />
            <input type="submit" name="register" id="register" value="Sign Up" data-theme="Sign Up" />
        </div>
    </div>
</body>

</html>

PHP page :

<?php
    $servername = "localhost";
    $username2  = "root";
    $password   = "";
    $dbname     = "joinx";
    // Create connection
    $conn       = new mysqli($servername, $username2, $password, $dbname);
    $conn->set_charset("utf8");

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } else {
        $username = $_POST['username'];
        $password = $_POST['password'];
        $email    = $_POST['email'];
        $q        = mysql_query("INSERT INTO `user` (`Username`,`Password`,`Email`) VALUES ('$username','$password','$email')");
        if ($q)
            echo "ok";
        else
            echo "error";
    }
?> 

EDIT : I said it doesn't work.I mean it doesn't happen anything! just like a HTML static page...

Ved
  • 2,701
  • 2
  • 22
  • 30
Maddox
  • 1
  • 1
  • 2
    Can you clarify what you mean by "it doesn't work"? are you getting an error message? Please edit your question to be more specific about what isn't working – Joel Apr 08 '16 at 01:10
  • hey @Fred -ii- open it please... it's not that – Maddox Apr 08 '16 at 01:30
  • 1
    `$q=mysql_query("INSERT INTO` that won't work with a `mysqli_` connection. So, if you're no longer mixing APIs, you should modify your question's code to reflect the syntax that should be used. I.e.: `$q=mysqli_query($conn, "INSERT INTO...` and should check for errors and tell us what it throws back. – Funk Forty Niner Apr 08 '16 at 01:34
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Apr 08 '16 at 01:35

1 Answers1

1

Cordova PhoneGap is a client-side framework for building hybrid apps. If I am not mistaken, you wish to run a server-side language in PhoneGap. This solution is simply not possible.

cnic
  • 480
  • 1
  • 5
  • 13