使用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?

douyong1886
douyong1886 请帮我
2 年多之前 回复
dpda53918
dpda53918 我会记住这一点先生。你能帮助我解决我的问题吗?逻辑似乎很好
2 年多之前 回复
douchan0523
douchan0523 不相关但是,在执行SQL查询时应该使用预准备语句来防止SQL注入。查看文档
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐