0

I am developing a simple application to save records on mysql database (xampp) using phonegap. However i am getting stucked somewhere. My code keeps writing "connecting..." for ever without saving the records on database. I researched all through but I cant seem to get the problem Please can somewhere show me my mistakes from my code? Thanks Maybe its the url, i am not sure, NOTE: My url is from the phonegap server.

 index.html
          <link rel="stylesheet" type="text/css" href="css/index.css" />
         <title>Hello World</title>
       </head>

  <body>
   <script src="jquery-3.1.1.min.js"></script>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script type="text/javascript" src="cordova.js"></script>
  <script type="text/javascript" src="js/index.js"></script>
  <script type="text/javascript">
    app.initialize();
    $(document).ready(function() 
        {
    $("#insert").click(function(){
        var firstname=$("#firstname").val();
        var lastname=$("#lastname").val();
        var phone=$("#phone").val();
        var dataString="firstname="+firstname+"&lastname="+lastname+"&phone="+phone+"&insert=";
        if($.trim(firstname).length>0 & $.trim(lastname).length>0 & $.trim(phone).length>0)
            {

        $.ajax({
        type: "POST",
        url: "http://10.250.216.195:3000/insert.php",
        data: dataString,

        crossDomain: true,
        cache: false,
        beforeSend: function(){ $("#insert").val('Connecting...');},
        success: function(data){
            if(data=="success"){
                console.log(data);
                alert("inserted");
                $("insert").val('submit');
            }
            else if (data=="error"){
                console.log(data);
                alert("error");
            }
        }

    });

    }   return false;
    });
      }



      );

       </script>
     <div data-role ="page" id ="page1">
     <div data-role ="header">
        <h1>Hello World</h1>
        <center><h3>Register</h3>
        <input type="hidden" id="id" value=""/>
        <label for ="Firstname" class="ui-hidden-accessible"></label> <input type = "text" id="firstname" placeholder ="firstname" required="required"><br>
         <label for ="Lastname" class="ui-hidden-accessible"></label> <input type = "text" id="lastname" placeholder ="lastname" required="required"><br>
        <label for ="Phone" class="ui-hidden-accessible"></label>       <input type = "text" id="phone" placeholder ="Phone" required="required"><br>
        <input type="button" value="insert" id = "insert"></center>


    </div>


 insert.php
   <?php
     include "dbconfig.php";
     if(isset($_POST['insert']))
   {
     $first=$_POST['firstname'];
     $last=$_POST['lastname'];
     $phone=$_POST['phone'];

     $first = mysqli_real_escape_string($con,$_POST['firstname']);
     $last = mysqli_real_escape_string($con,$_POST['lastname']);
     $phone = mysqli_real_escape_string($con,$_POST['phone']);

    $q=mysqli_query($con,"INSERT INTO phone (firstname,lastname,phone) VALUES ('$first','$last','$phone')");
  if($q)
 echo "success";
   else
    echo "error";
  }
  ?>

1 Answers1

0

If you are using an XAMPP server I am presuming the server is on the same computer you are developing on.

If this is the case test the phonegap app in your browser using google chrome and change your URL to:

http://10.250.216.195/insert.php

Port 3000 is for phonegap build testing. the above URL should work fine.

James Mallon
  • 1,107
  • 9
  • 25
  • Yes , i am using the same computer, i did change the url to the above mentioned without the port 3000 but it still is not working. – oolaosebikan Mar 29 '17 at 23:17