duanbishai5271 2016-05-06 12: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 13: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.

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

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部