0

I need your help to correct my code. I used this code to update my database. I get the message:

Data Updated Successfully

But there is no update.

My fragmentx.java: In this fragment there is a listview:

public class fragmentEx extends Fragment implements ListView.OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(getActivity().getApplicationContext(), ViewUser.class);
        HashMap<String, String> map = (HashMap) parent.getItemAtPosition(position);
        String id = map.get("id").toString();
        intent.putExtra("type", id);
        startActivity(intent);
    }
}

View.java: In this fragment there is the edittext and the updatebutton:

public class View extends FragmentActivity{
    private TextView editId;
    private EditText editN;
    private EditText editD;
    private EditText editS;

    private Button buttonUpdate;
public static final String URL_UPDATE_EMP="http://10.0.3.2/PHP/updateAll.php";
 private void updateEmployee(){
        final String id = editId.getText().toString().trim();
        final String Num = editN.getText().toString().trim();
        final String Dec = editD.getText().toString().trim();
        final String Style = editS.getText().toString().trim();

        class UpdateEmployee extends AsyncTask<Void,Void,String>{
            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewUser.this,"Updating...","Wait...",false,false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                Toast.makeText(View.this,s,Toast.LENGTH_LONG).show();
            }

            @Override
            protected String doInBackground(Void... v) {
                HashMap<String,String> params = new HashMap<>();
                // params.put("id",login11);
                params.put("Log",cal);
                params.put("num",Num);
                params.put("dec",Dec);
                params.put("style",Style);

                RequestHandler rh = new RequestHandler();

                String s = rh.sendPostRequest(URL_UPDATE_EMP, params);

                return s;
            }
        }

        UpdateEmployee ue = new UpdateEmployee();
        ue.execute();
    }
}

updateAll.php:

<?php 
    if($_SERVER['REQUEST_METHOD']=='POST'){
    require_once('dbConnect.php');
        $num= $_POST['num'];
        $dec= $_POST['dec'];
        $style= $_POST['style'];

        $sql = "UPDATE tab2 SET Desc = '$dec', Style = '$style' WHERE Num = '$num'";
                //Executing query to database
        if(mysqli_query($con,$sql)){
            echo 'Data Updated Successfully';
        }else{
            echo 'Could Not Update Data Try Again';
        }

        //Closing the database 
        mysqli_close($con);
        }
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
sonia_
  • 21
  • 4

0 Answers0