如何使用变量

时间:2017-08-30 14:39:01

标签: java php android sql httpurlconnection

我有一些数据,我将一个httpurlconnection传递给一个php脚本,该脚本获取已经通过urlencoder编码的变量,现在我想从脚本中获得一个回复,我可以用回声来做这个但是不会解决我的问题我想在不同的变量中保存数据,就像使用Android部分的url编码器完成它,然后将这些变量发送回android设备。我怎么能这样做呢。这是用于发送数据和接收响应的代码

 String data = URLEncoder.encode("studentschool","UTF-8")+"="+URLEncoder.encode(getStudentSchool,"UTF-8")+"&"+
                  URLEncoder.encode("studentdepartment","UTF-8")+"="+URLEncoder.encode(getStudentDepartment,"UTF-8")+"&"+
                  URLEncoder.encode("studentcurrentyear", "UTF-8")+"="+URLEncoder.encode(getStudentCurrentYear, "UTF-8");

            bufferedWriter.write(data);
            bufferedWriter.flush();
            bufferedWriter.close();
            outputStream.close();

            InputStream inputStream = httpURLConnection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String response = " ";
            String line = "";
            while ((line = reader.readLine()) != null){
                response+=line;
            }
            reader.close();
            httpURLConnection.disconnect();
            inputStream.close();
            return response;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

这是我的php

require "init.php";

$school = @$_POST["studentschool"];
$department = @$_POST["studentdepartment"];
$school_year = @$_POST["studentcurrentyear"];

$query = "SELECT *
              FROM `users`
              WHERE `school` = '$school'
               AND  `department` = '$department'
               AND  `schoolyear` = '$school_year'
                AND `courserep` = '1' LIMIT 1";

$result= mysqli_query($link,$query);

if (mysqli_num_rows($result)> 0){
  $row = mysqli_fetch_assoc($result);
  $monday = $row["Monday"];
  $tuesday = $row["Tuesday"];
  $wednesday = $row["Wednesday"];
  $thursday = $row["Thursday"];
  $friday = $row["Friday"];

  echo $monday;
  echo $tuesday;
}

0 个答案:

没有答案