I am developing an application for a restaurant control, it should be noted that I am relatively new to this, and most of what I do is with online consultations.
This is the problem, I have this PHP Script in which I receive a variable of NAME with the name of a food dish, and returns the id the name, price and what you can see .
<?php
// Getting the requested id
$NOMBRESEND = $_GET['NOMBRE'];
// Importing database
require_once('connectdb.php');
// Creating SQL query with where clause to get a specific employee
$sql = "SELECT c.NOMBRE AS NOMBRECATEGORIA, p.* FROM plato p, categoria c WHERE p.ID_CATEGORIA=c.ID_CATEGORIA AND (p.NOMBRE=$NOMBRESEND OR c.NOMBRE=$NOMBRESEND)";
// getting result
$r = mysqli_query($con,$sql);
// creating a blank array
$result = array();
while($row = mysqli_fetch_array($r)){
// Pushing name and id in the blank array created
array_push($result,array(
"ID_PLATO"=>$row['ID_PLATO'],
"NOMBRE"=>$row['NOMBRE'],
"PRECIO"=>$row['PRECIO'],
"DESCRIPCION"=>$row['DESCRIPCION'],
"NOMBRECATEGORIA"=>$row['NOMBRECATEGORIA'],
));
}
// displaying in JSON format
echo json_encode(array('result'=>$result));
mysqli_close($con);
?>
The script works well. The problem is in Android. I control the name of the cymbal with this function:
public String sendGetRequestParam(String requestURL, String id){
StringBuilder sb =new StringBuilder();
try {
URL url = new URL(requestURL+"\""+id+"\"");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String s;
while((s=bufferedReader.readLine())!=null){
sb.append(s+"\n");
}
}catch(Exception e){
}
return sb.toString();
}
Where requestURL
is the address of the PHP script and id
is the name of the cymbal.
If in that variable id
I send for example "pizza" the value returns correctly and it shows me the JSON file with the saucer, but if I send for example "Chicken burger" it does not return any JSON. The weird thing is that if I do it with postman, for example and I write "Chicken Burger" if I return the JSON as you can see in this image:
In the debug these data come out in both cases.
In this I send "Ravioli" and as you can see in the String s
return the JSON with the data of the ravioli.
But when you send it for example "Chicken burger" it does not return anything and does not save the data in the String s
and it does not receive the JSON with them either.