Data is not inserted from android to mysql using Volley

Asked

Viewed 122 times

1

I asked this question from link and the problem I was having was solved. But I still can’t enter data into the database.

Connection.php

<?php
    $mysql_hostname = "localhost";
    $mysql_user = "root";
    $mysql_password = "";
    $mysql_database = "app";

    $db = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
    mysql_select_db($mysql_database, $db) or die("Opps some thing went wrong");

?>

Insert.php

<?php
        error_reporting(0);
        include("connection.php");

       // vetor response
       $response = array();

       if( !(empty($_POST['matricula']))){
           //variaveis recebendo os valores pelo método POST
           $matricula=$_POST['matricula'];
           $cpf=$_POST['cpf'];
           $placa=$_POST['placa'];

           $result = mysql_query("INSERT INTO myorder(idUser,matricula,cpf,placa) VALUES('','$matricula','$cpf','$placa')");   
           if($result>0){
              $response["success"] = 1;
           }   
           else{
              $response["success"] = 0;
           }

        echo json_encode($response);
      }

?>

Request

StringRequest postRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            PD.dismiss();
            matricula.setText("");
            cpf.setText("");
            placa.setText("");
            Toast.makeText(getApplicationContext(),
                    "Data Inserted Successfully",
                    Toast.LENGTH_SHORT).show();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            PD.dismiss();
            Toast.makeText(getApplicationContext(),
                    "Fail", Toast.LENGTH_SHORT).show();
        }
    }) {
        @Override
        protected Map<String, String> getParams(){
            Map<String, String> params = new HashMap<String, String>();
            params.put("matricula", item_matricula);
            params.put("cpf", item_cpf);
            params.put("placa", item_placa);
            return params;
        }
    };
ConMain2.getInstance().addToReqQueue(postRequest);

Below is the message that appears in logCat:

 11-20 16:28:07.560    2567-2567/? D/AndroidRuntime﹕ >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
 11-20 16:28:07.560    2567-2567/? D/AndroidRuntime﹕ CheckJNI is ON
 11-20 16:28:07.580    2567-2567/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
 11-20 16:28:07.580    2567-2567/? E/android.os.Debug﹕ failed to load memtrack module: -2
 11-20 16:28:07.580    2567-2567/? D/AndroidRuntime﹕ Calling main entry com.android.commands.am.Am
 11-20 16:28:07.580    1293-1325/? W/InputDispatcher﹕ channel '1cba05e4 br.fepi.caronasfepi/br.fepi.caronasfepi.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
 11-20 16:28:07.580    1293-1325/? E/InputDispatcher﹕ channel '1cba05e4 br.fepi.caronasfepi/br.fepi.caronasfepi.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
 11-20 16:28:07.580    1293-2247/? I/WindowState﹕ WIN DEATH: Window{1cba05e4 u0 br.fepi.caronasfepi/br.fepi.caronasfepi.MainActivity}
 11-20 16:28:07.580    1293-2247/? W/InputDispatcher﹕ Attempted to unregister already unregistered input channel '1cba05e4 br.fepi.caronasfepi/br.fepi.caronasfepi.MainActivity (server)'
 11-20 16:28:07.630    1589-1731/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
 11-20 16:28:07.630    1589-1731/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f19aecdd740, error=EGL_SUCCESS
 11-20 16:28:07.640    1293-2338/? W/InputMethodManagerService﹕ Got RemoteException sending setActive(false) notification to pid 2548 uid 10053
 11-20 16:28:07.910    2580-2580/? D/AndroidRuntime﹕ >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
 11-20 16:28:07.930    2580-2580/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
 11-20 16:28:07.930    2580-2580/? E/android.os.Debug﹕ failed to load memtrack module: -2
 11-20 16:28:07.940    2580-2580/? D/AndroidRuntime﹕ Calling main entry com.android.commands.am.Am
 11-20 16:28:07.950    1293-2341/? V/WindowManager﹕ addAppToken: AppWindowToken{25fd608b token=Token{f81565a ActivityRecord{27cd5605 u0 br.fepi.caronasfepi/.MainActivity t322}}} to stack=1 task=322 at 0
 11-20 16:28:07.960    2589-2589/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
 11-20 16:28:07.970    1293-2339/? I/ActivityManager﹕ Start proc 2589:br.fepi.caronasfepi/u0a53 for activity br.fepi.caronasfepi/.MainActivity
 11-20 16:28:08.060    2589-2604/? D/﹕ HostConnection::get() New Host Connection established 0x7f19aece64c0, tid 2604
 11-20 16:28:08.070    2589-2604/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4
 11-20 16:28:08.090    2589-2604/? D/OpenGLRenderer﹕ Enabling debug mode 0
 11-20 16:28:08.100    2589-2604/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
 11-20 16:28:08.100    2589-2604/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f19aeceb700, error=EGL_SUCCESS
 11-20 16:28:08.140    1293-1316/? I/ActivityManager﹕ Displayed br.fepi.caronasfepi/.MainActivity: +190ms
 11-20 16:28:11.620    1293-1350/? D/TaskPersister﹕ removeObsoleteFile: deleting file=321_task.xml
  • 1

    In the method onErrorResponse() replace, in Toast, the string "Fail" by error.NetworkResponse.statusCode and say what value appears.

  • Appears the Unfortunately app stop

  • I put the following code:Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();&#xA; VolleyLog.e("Error: ", error.getMessage()); And returned me the following reply java.lang.RuntimeException: Bad url .meu ip/insert.php where in place of my ip is the ip address of my server.

  • 1

    I got it, just put the http before the ip.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.