How to send various data from android to php

2

Good morning I am doing an application in android studio I am using php to make my connection with the database MYSQL .

But when I make a query with a single argument to my database it works but I make a modification to send two arguments and validate my php and the query works properly but ** Android ** tells me an error I'm looking for information but I do not understand what I'm doing wrong annex my code

android

public class Principal extends AppCompatActivity {

  Spinner opciones;
  Button Consultar;
  EditText Cons;
  JSONArray ja;
  Tabla_Consulta tabla;
  LinearLayout linearLayout;

  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    opciones = (Spinner) findViewById(R.id.spinner);
    Consultar = (Button) findViewById(R.id.button_consultar);
    Cons = (EditText) findViewById(R.id.editText_Consulta);
    tabla = new Tabla_Consulta(this, (TableLayout) findViewById(R.id.tabla));





    ArrayAdapter < CharSequence > adapter = ArrayAdapter.createFromResource(this, R.array.Opc, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.preference_category);
    opciones.setAdapter(adapter);


    Consultar.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        String selec = opciones.getSelectedItem().toString();
        String selec1 = Cons.getText().toString();

        Consulta("http://10.0.2.2/Libro_Titulo.php?eje=" + opciones.getSelectedItem().toString() + "&" + "Tit=" + Cons.getText().toString());
        //Consulta("http://10.0.2.2/Biblioteca/Libro_Id.php?ide="+Cons.getText().toString());
        //     Log.d("query",   );
        Log.d("query", selec + " " + Cons.getText().toString());
        Log.d("query", selec + " " + selec1);      

      }
    });
  }

  private void Consulta(String URL) {
    Log.i("conexion", URL);
    RequestQueue queue = Volley.newRequestQueue(this);

    StringRequest stringRequest = new StringRequest(Request.Method.GET, URL, new Response.Listener < String > () { //EL ERROR ESTA EN ESTA LINEA

      @Override
      public void onResponse(String response) {
        int j = 1;
        Log.d("reponse", response);
        try {

          ja = new JSONArray(response);
          tabla.agregarCabecera(R.array.Opciones);

          for (int i = 0; i < ja.length(); i++) {

            JSONObject c = ja.getJSONObject(i);


            String id = c.getString("Id");
            String Titulo = c.getString("Titulo");
            String Autor = c.getString("Autor");
            String Editorial = c.getString("Editorial");
            String Facultad = c.getString("Facultad");
            String Reserva = c.getString("Reserva");

            if (Reserva.equals("0")) {
              Reserva = Reserva.replace("0", "Libre");
            } else if (Reserva.equals("1")) {
              Reserva = Reserva.replace("1", "Reserva");
            }

            ArrayList < String > elementos = new ArrayList < String > ();


            elementos.add(Integer.toString(j));
            elementos.add(id);
            elementos.add(Titulo);
            elementos.add(Autor);
            elementos.add(Editorial);
            elementos.add(Facultad);
            elementos.add(Reserva);
            elementos.add("BUTTON");
            tabla.agregarFilaTabla(elementos);
            j++;
          }


        } catch (JSONException e) {
          e.printStackTrace();
        }

      }
    }, new Response.ErrorListener() {
      @Override

      public void onErrorResponse(VolleyError error) {

      }
    });
    queue.add(stringRequest);
  }
}

Error:

  

04-17 15: 31: 01.276 11093-11238 / com.example.ferney.bibliotecacur E / Volley: [429] BasicNetwork.performRequest: Unexpected response code 404 for link

php

< ? php
header('Content-Type: text/html;charset=utf-8');
include('Conectar.php');
$Tit = $_GET["Tit"];
$eje=$_GET["eje"]; // para solo un archivo
$rawdata = array(); //creamos un array

if ($resultset = getSQLResultSet("SELECT * FROM 'tbl_libro' WHERE $eje='$Tit'")) {

  
  $rawdata = array(); //creamos un array

  $i = 0;

  while ($row = mysqli_fetch_array($resultset)) {
    
    $rawdata[$i] = $row;
    $i++;

  }

  echo json_encode($rawdata);
}
    
asked by esteban fabian patiño 17.04.2018 в 18:11
source

2 answers

3

The error indicates that you are sending an incorrect parameter or your php has an error:

  

com.example.ferney.bibliotecacur E / Volley: [429]   BasicNetwork.performRequest: Unexpected response code 404 for    link

Although remember the code of error 404 indicates that you can not find a resource.

a problem is the query that you are forming is incorrect:

"SELECT * FROM 'tbl_libro' WHERE $eje='$Tit'"

must be done in this way to obtain the desired values and concatenate them to the Query:

"SELECT * FROM tbl_libro WHERE ".$eje."='".$Tit."'"
    
answered by 17.04.2018 / 18:54
source
0

Error was URL addressing

 Consulta("http://10.0.2.2/Biblioteca/Libro_Titulo.php?eje="+ opciones.getSelectedItem().toString() +"&Tit=" + Cons.getText().toString());
              

The error was that the url address is wrong because it is not indicated where the project is (Library) for that reason could not find where the php file

    
answered by 18.04.2018 в 20:24