Hi, I am programming an app and facing a problem now. I want to Update my Database over the GUI from my App via PHP. My Problem is that the app always sends the value of the checkbox even if it is unchecked. I will post my Script below.
update.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$id = $_GET['id'];
$name= $_POST['Name'];
$surname = $_POST['Surname'];
$blood_typeA = _POST['Blood_TypeA'];
$blood_typeB = _POST['Blood_TypeB'];
$blood_type0 = _POST['Blood_Type0'];
$blood_typeAB = _POST['Blood_TypeAB'];
require_once('dbConnect.php');
$sql = "UPDATE T_Student SET Name = '$name', Surname ='$surname', Blood_Type = '$blood_typeA,$blood_typeB,$blood_type0,$blood_typeAB' WHERE ID = $id";
if(mysqli_query($con,$sql)or die('Error in query: $sql' . mysqli_error($con))){
echo 'Student updatet';
}else{
echo 'Error try again';
}
mysqli_close($con);
}
?>
My java code
private void updateStudent(){
final String Name = etName.getText().toString().trim();
final String Surname = etSurname.getText().toString().trim();
final String BloodTypeA = checkBoxBloodA.getText().toString().trim();
final String BloodTypeB = checkBoxBloodB.getText().toString().trim();
final String BloodType0 = checkBoxBlood0.getText().toString().trim();
final String BloodTypeAB = checkBoxBloodAB.getText().toString().trim();
class UpdateStudent extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(getActivity(),"Updating...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getActivity(),s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(Void... params) {
HashMap<String,String> hashMap = new HashMap<>();
hashMap.put("Protokoll",Protkoll);
hashMap.put("Name",Name);
hashMap.put("Surname",Surname);
hashMap.put("Blood_TypeA",BloodTypeA);
hashMap.put("Blood_TypeB",BloodTypeB);
hashMap.put("Blood_Type0",BloodType0);
hashMap.put("Blood_TypeAB",BloodTypeAB);
Connection con = new Connection();
String request = con.sendPostRequest("MY ADRESS.php?id=" + ID_Student, hashMap);
return request;
}
}
UpdateStudent update = new UpdateStudent();
update.execute();
}
@Override
public void onClick(View v) {
if(v == buttonUpdate){
updateStudent();
}
}