Reputation: 105
I want to ask something regarding my project. In my App, there's an EditText that need to be input by the user and after that the user must click button "save" to save the input data to mysql database. I do it successfully, which means the data has been saved.
But the problem is, the android apps don't show the message "Data saved". This message I wrote it PHP.
Below is my code:
JAVA
private void createTask(final String task_name, final String badgeid) {
StringRequest stringRequest=new StringRequest(Request.Method.POST, URLs.URL_ADD_TASK, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String, String> getParams() {
Map<String,String>parms=new HashMap<String, String>();
parms.put("task_name",task_name);
parms.put("badgeid",badgeid);
return parms;
}
};
RequestQueue requestQueue= Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);
}
PHP
<?php
require_once "../config/configPDO.php";
$task_name = $_POST['task_name'];
$badgeid = $_POST['badgeid'];
$sql = "INSERT INTO report (task_name, badgeid, report_date, report_status) VALUES('$task_name','$badgeid', NOW(), 'Pending')";
$query = $conn->prepare($sql);
$query->execute();
if($query){
echo "Data Save!";
}else{
echo "Error!! Not Saved";
}
?>
Upvotes: 0
Views: 88
Reputation: 1028
Just Toast your response in onResponse
Callback of StringRequest
Like,
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this,response.toString(),Toast.LENGTH_LONG).show();
}
Upvotes: 2