设置时间删除预订php

时间:2014-01-31 10:23:17

标签: php mysql

我正在尝试在预订系统中设置时间限制。用户必须这样 有能力删除他们的预订,但不能在距离预订时间1分钟之前删除

 <?php 
 require_once 'connection.php';


if(isset($_SESSION['book'])){

if (isset($_SESSION['book_time'])){
    if (time()-$_SESSION['book_time']>= 60){

        if (isset($_POST['delete'])){       

$machineID = $_POST['machine_id'];
$starttime = $_POST['start_time'];

$qry = "DELETE FROM bookings where machine_id = '$machineID' AND 
 start_time = '$starttime'";

$result =  mysql_query($qry,$conn);
if ($result){

    if(mysql_affected_rows()>0){
        $message[] = 'Booking Deleted form DB';
    }
  }

    }
}
 }
  }
?>

但即使在1分钟后使用此脚本也无法删除....可能出现的问题

2 个答案:

答案 0 :(得分:0)

更改

if (isset($_POST['delete'])){       

$machineID = $_POST['machine_id'];
$starttime = $_POST['start_time'];

if (isset($_POST['delete']) && (time()-$_SESSION['book_time']>= 60)){       

$machineID = $_POST['machine_id'];
$starttime = $_POST['start_time'];

答案 1 :(得分:0)

试试这个......

iF ((int)$starttime+60 > time()) {
$qry = "DELETE FROM bookings where machine_id = '$machineID' AND start_time = '$starttime'";
}