参数未传递给php

时间:2017-07-31 09:03:09

标签: android

我检查过,该方法成功接收变量。但由于一些奇怪的原因,它没有传递给PHP,我无法弄清楚为什么。对于寄存器和登录功能,我使用了相同的方式传递数据和接收来自php的响应。他们工作正常。

后台AsyncTask

      String update_id = params[1];
        System.out.println("*************");
        System.out.println(update_id);
        System.out.println("*************");
        try {
            URL url = new URL(update_url);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);


            OutputStream OS = httpURLConnection.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS,"UTF-8"));
            String data = URLEncoder.encode("login_id","UTF-8") + "=" + URLEncoder.encode(update_id, "UTF-8");
            OS.write(data.getBytes());
            bufferedWriter.write(data);
            bufferedWriter.flush();
            OS.close();


            InputStream is = httpURLConnection.getInputStream();
            is.close();

            BufferedReader bufferedReader = new BufferedReader(new 
                          InputStreamReader(url.openStream()));
            String inputLine;
            while((inputLine = bufferedReader.readLine()) != null){
                sb.append(inputLine);
            }
            return "update";
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e){
            e.printStackTrace();
        }

Update.php       

    require "init.php";
    $update_id = $_POST["login_id"];

    $sql_query="select * from test where id = '$update_id'";

    $result = mysqli_query($con,$sql_query);

    if ($result->num_rows > 0) {
           while($row = $result->fetch_assoc()) {
                 echo $row["id"];
                 echo ("split");
                 echo $row["name"];
                 echo ("split");
                 echo $row["address"];
    }
    } else {
          echo $update_id;
          // echo "0 results";
    }

?>

AccountDetailsFragment.java

 @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    LayoutInflater lf = getActivity().getLayoutInflater();
    v = lf.inflate(R.layout.fragment_account_details, container, false);

    update_id = (EditText) v.findViewById(R.id.et_id_edit);
    update_name = (EditText) v.findViewById(R.id.et_Name_edit);
    update_address = (EditText) v.findViewById(R.id.et_address_edit);

    login_id = Login.login_id();
    login_name = Login.login_name();

    getActivity().setTitle("Account Details");
    String method = "update";
    Background background = new Background(getContext());
    background.execute(method, login_id);

    update_id.setText(idd);
    update_name.setText(namee);
    update_address.setText(addresss);

        }
    });

    return v;
}

Login.java

 public void userLogin(View v) {
    id = et_id.getText().toString();

    if (!id.isEmpty() && !name.isEmpty()) {
        String method = "login";
        Background background = new Background(getApplicationContext());
        background.execute(method, id, name);
        AccountDetailsFragment adf = new AccountDetailsFragment();
    } else {
        Toast.makeText(Login.this, "Please fill any empty fields", 
                 Toast.LENGTH_SHORT).show();
    }

  }
  public static String login_id(){
     return id;
  }

0 个答案:

没有答案
相关问题