dongque1462 2017-11-29 05:46
浏览 60

使用webservice更新mysql表中的列正在通过直接访问php文件,但不是在android中运行应用程序时

Remark.java:

This acts like a backgroundworker and posts data through coordinating with my php in my htdocs:

List<NameValuePair> nameValuePairs;
        nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("input", inputString.trim()));

        try {
            String Url = "http://192.168.x.x/webservices/scwebservice/"+command+".php"; 
            httpclient = new DefaultHttpClient();

            String riddleIDValString = URLEncoder.encode(inputString,"UTF-8");
            Url = Url+"?input="+riddleIDValString;
            httpost = new HttpPost(Url);

            httpost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            response = httpclient.execute(httpost);
            inputStream = response.getEntity().getContent();

            data = new byte[256];

            buffer = new StringBuffer();

            int len = 0;

            while (-1 != (len = inputStream.read(data)) ) {
                buffer.append(new String(data, 0, len));
            }
            //for the output or echo
            final String bufferedInputString = buffer.toString();

            inputStream.close();
            ((Activity) context).runOnUiThread(new Runnable() {
                  public void run() {
                    Toast.makeText(context, bufferedInputString, Toast.LENGTH_SHORT).show();
                  }
                });
            }

This is my another java class, it passes the data to my Remarks.java (sample data it passes:"2014102002:myremark"), Im also passing my "UPDATE-REMARK" in the REMARK.java to know the php file to use.

Remark update = new Remark(StudentprofileActivity.this,"UPDATE-REMARK");
        switch (arg0.getId()) {
        case R.id.btnsave:
            update.execute(id+":"+edittextremarks.getText().toString());
            break;  
        }

This is my PHP file in htdocs, it coordinates with my Remarks.java, and receives the input "2014102002:myremark", the php file will explode it and then update column remark in my database (the id is an int, and the remark is varchar):

$link = mysql_connect("localhost", "root", "");
mysql_select_db("my_db", $link);

$remarkinfo = $_POST['input'];
$data = explode(":",$remarkinfo);
$studid=(int)$data[0];
mysql_query("UPDATE attendance_tbl SET remarks = '$data[1]' where student_id = $studid") or die(mysql_error());
echo $remarkinfo;

Im trying to execute my php file in the browser url, it is updating my column but when im trying to run the app in my phone it doesn't update the column. Can you check what's wrong in my Remark.java? Or if i have something to improve in the php file?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码