SQL UPDATE查询无法更新某些时间 - PHP预订系统

时间:2013-09-30 08:37:59

标签: php jquery sql ajax

我使用SQL,php和Javascript / Jquery构建了一个简单的预订系统。我也在使用AJAX。想法是向用户呈现可用时隙列表,并且当用户选择一个所选时隙应该自动消失时(可用时隙通过AJAX再次重新加载)并且因此对其他用户不可用。每个时隙都作为html td元素输出,其中包含一个链接,该链接存储时间段“id”(在数据库中设置)作为该超链接的属性。单击时间段时,使用AJAX将时隙id发送到下面的php函数。根据数据库中存储的可见性列是零还是一个来显示时间段。

我正在用相当多的用户对此进行测试,我注意到每隔一段时间(可能每20或30次预订一次),负责将时隙可用性值更新为零的SQL UPDATE查询似乎不是做它应该做的事情,价值保持在一个,从而导致偶尔的双重预订。

否则,一切都运行得很好 - 我尽可能地与同事一起测试了应用程序,我无法复制问题,但双重预订显然不是一个选择。可能有人知道会出现什么问题吗?

提前感谢任何建议/帮助。

    public function makebooking($user, $timeslotUID, $timeslot, $edits) {        

        $username = $user->username;
        $user_fn = $user->displayname;      
        $plgID = $user->plg;    //The 'PLG' is the person who the user is booking an appointment with   

        $user = $edits['user'];
        $currentDate = $edits['date'];

        $json = new JSON();     
        $json->user = stripslashes($user);
        $json->currentDate = $currentDate;

                   //Problem seems to occur here..
        $q1 = " UPDATE plg_timeslots
        SET visible = 0
        WHERE id= '$timeslotUID';" ;

        $res1 = $this->dbcon->query($q1);


        //If the user already has a booking they are rearranging
        $currentBooking =  $this->getBookings($username, 'STU');

        if($currentBooking) {   

                //Reinstate previous timeslot
                $q2 = "UPDATE plg_timeslots
                       SET visible = 1
                WHERE id= '$timeslotUID';" ;        

                $res2 = $this->dbcon->query($q2);

                //Update current booking
                $q3 = "UPDATE bookings 
                            SET timeslot_id = '$timeslotUID',
                            timeslot = '$timeslot',
                            edited_by = '$user',
                            edited_when = '$currentDate'
                            WHERE user_id = '$username' ;";     

                $res3 = $this->dbcon->query($q3);

            } else {   //If no booking is present, make a new booking

                    $q4 = "INSERT INTO bookings (plg_id, user_id, timeslot_id, timeslot, 
                                 edited_by, user_fn, edited_when)
                                 VALUES ('$plgId', '$username' ,'$timeslotUID', 
                                 '$timeslot', '$user', '$user_fn', 
                                 '$currentDate');";   

                    $res4 = $this->dbcon->query($q4);
            } 


            return $json;

    }

0 个答案:

没有答案