duanbishai5271 2016-05-06 20:07
浏览 41
已采纳

我不知道在使用Volley更新数据库时我做错了什么

In my program I have ListView of rooms(only available are shown). Tapping on one of items results in showing a layout with details like price etc. Also here is a book button. If user is logged in it should book the room (update the database and set 'available' property of certain room to 0). If not, user should log in.

Everything works fine except update operation.

So, this is my PHP script, which should update database

<?php 
 if($_SERVER['REQUEST_METHOD']=='POST'){

 $id = $_POST['id'];
 $available = $_POST['available'];

//importing database connection script 
 require_once('dbConnect.php');

 //Creating sql query 
 $sql = "UPDATE room SET available = '$available' WHERE id = $id";

 //Updating database table 
 if (mysqli_query($con,$sql)) {
 echo 'Room Is Booked Successfully';
 }
 else {
 echo 'Could Not Book Room, Try Again';
 }

 //closing connection 
 mysqli_close($con);
 }

This is my android volley function:

private void update() {
        available = Integer.valueOf(0).toString();
        id = Integer.valueOf(Config.SELECTED_ITEM + 1).toString();
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.BOOK_URL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Toast.makeText(DetailsActivity.this, response, Toast.LENGTH_LONG).show();
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(DetailsActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
                    }
                }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put(Config.KEY_ID, id);
                params.put(Config.KEY_AVAILABLE, available);
                return params;
            }
        };

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }

Everytime I'm getting this message: Could Not Book Room, Try Again. Help me please.

  • 写回答

1条回答 默认 最新

  • douyi1197 2016-05-06 21:48
    关注

    Already solved my problem. I am so stupid. The problem was in dbConnect.php, which is connecting to users database, not to roomspar, where room table is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决