This is my code
Sometimes i dont get an empty string.
EditText ord;
TextView fintext;
Button send;
RequestQueue requestQueue;
String insertUrl = "myurl";
requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
StringRequest request = new StringRequest(Request.Method.POST, insertUrl, 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() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("ord", ord.getText().toString());
return parameters;
}
};
requestQueue.add(request);
Toast.makeText(getActivity(), "Tack, vi kontrollerar nu ordet.",
Toast.LENGTH_SHORT).show();
ord.setText("");
}
PHP file
if($_SERVER["REQUEST_METHOD"]=="POST"){
require 'connection.php';
createStudent();
}
function createstudent()
{
global $connect;
$firstname = $_POST["ord"];
$query = " Insert into charader(ord) values ('$firstname');";
$query2 = " Insert into rita(ord) values ('$firstname');";
mysqli_query($connect, $query) or die (mysqli_error($connect));
mysqli_query($connect, $query2) or die (mysqli_error($connect));
mysqli_close($connect);
}
1 Answer(s)