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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?