duanlieshuang5330 2016-11-29 07:47
浏览 26

如何在PHP中获取表ID并在android中更新?

In my android app. When i update the scores of teams, everything in the database updates. How can i get the id of a column in php and android? How can i update values in my database using android by getting the id?

PHP

<?php 

 $teamone = $_POST["teamone"];
 $teamtwo = $_POST["teamtwo"];
 $teamonepts = $_POST["teamonepts"];
 $teamtwopts = $_POST["teamtwopts"];



 require_once('init.php');


 $sql = "UPDATE matches SET teamone = '$teamone',  teamonepts = '$teamonepts', teamtwo = '$teamtwo', teamtwopts = '$teamtwopts'";


 if(mysqli_query($con,$sql)){
 echo 'Updated';
 }else{
 echo 'Failed';
 }


 mysqli_close($con);

?>

Here is my android code

else if(method.equals("send"))
        {

            String teamone = params[1];
            String teamonepts = params[2];
            String teamtwo = params[3];
            String teamtwopts = params[4];
            try {
                URL url = new URL(send_url);
                HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                OutputStream os = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                String data = URLEncoder.encode
                        ("teamone", "UTF-8")+"="+ URLEncoder.encode(teamone, "UTF-8")+"&"+
                        URLEncoder.encode("teamonepts", "UTF-8")+"="+ URLEncoder.encode(teamonepts, "UTF-8")+"&"+
                        URLEncoder.encode("teamtwo", "UTF-8")+"="+ URLEncoder.encode(teamtwo, "UTF-8")+"&"+
                URLEncoder.encode("teamtwopts", "UTF-8")+"="+ URLEncoder.encode(teamtwopts, "UTF-8");
                bufferedWriter.write(data);
                bufferedWriter.flush();
                bufferedWriter.close();
                os.close();
                InputStream IS = httpURLConnection.getInputStream();
                IS.close();
                httpURLConnection.disconnect();

                return "Data Sent";

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }


        }
        return null;
    }

Here is my table

Here is my table

展开全部

  • 写回答

0条回答 默认 最新

      编辑
      预览

      报告相同问题?

      手机看
      程序员都在用的中文IT技术交流社区

      程序员都在用的中文IT技术交流社区

      专业的中文 IT 技术社区,与千万技术人共成长

      专业的中文 IT 技术社区,与千万技术人共成长

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      客服 返回
      顶部