0

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();

        }

    }
Attachments mysql_database2.PNG 5.38 KB gui.PNG 12.13 KB mysql_database.PNG 5.09 KB
3
Contributors
6
Replies
24
Views
2 Years
Discussion Span
Last Post by cereal
0

Your code is your responsibility, but here's a trivial example you can adapt:

String s;
if (myCheckBox.isSelected()) 
   s= "option is selected":
else
  s = "option is not selected";
0

Ok thx I tried it, but it didn't worked with isSelected(). It worked withisChecked() but thx anyway :)

Edited by Natsu123

0

By the way, you're missing the $ symbol in the $_POST array:

$blood_typeA = _POST['Blood_TypeA'];
$blood_typeB = _POST['Blood_TypeB'];
$blood_type0 = _POST['Blood_Type0'];
$blood_typeAB = _POST['Blood_TypeAB'];

Should be:

$blood_typeA = $_POST['Blood_TypeA'];

And so on.

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.