I am using volley to make a POST request in HTTP to an API in PHP that I created. This API will insert in a database the value it receives. Your code is as follows:
//datos para la conexión
$usuario = "******";
$password = "******";
$servidor = "*******";
$basedatos = "*******";
//creacion de la conexion
$conn = mysqli_connect($servidor, $usuario, $password) or die("Fallo en la conexión");
$db = mysqli_select_db($conn, $basedatos);
$name = $_POST["name"];
//sentencia sql y ejecución de esta
$sql = "INSERT INTO txumino VALUES($name)";
mysqli_query($conn,$sql) or die("Error");
//cerrando la conexíon
mysqli_close($conn);
The Android code with which I make this request is the following:
StringRequest sr = new StringRequest(Request.Method.POST, URL_POST, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplication(),response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplication(),error+"", Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String,String> getParams() throws AuthFailureError{
Map<String,String> params = new HashMap<String, String>();
params.put("name",n);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(sr);
This code is inside a function that I call when I press a button. This would send the PHP API the value of an editText.
The errors that I receive in the Logcat when executing the code are the following:
KnoxVpnUidStorageknoxVpnSupported API value returned is false
D / ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
I / System.out: (HTTPLog) -Static: isSBSettingEnabled false
D / ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
On the other hand, in the TOAST message that appears on the screen, only "Error" appears without specifying because it was the same and when looking at the database, nothing new has been inserted.