Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何验证用户从mysql数据库中删除记录_Php_Mysql - Fatal编程技术网

Php 如何验证用户从mysql数据库中删除记录

Php 如何验证用户从mysql数据库中删除记录,php,mysql,Php,Mysql,我目前有一个预订系统,允许用户查看、编辑和删除记录。系统目前允许用户随时删除记录。但是,由于它是一个预订系统,因此用户只能在预订日期前48小时删除记录,并应限制用户在预订日期后24小时内删除记录。我是否需要包含某种函数 这是我删除记录的当前代码: bookings.php echo "<td><a href = 'delete.php?id=".$row['booking_id']."' onclick='return confirmation

我目前有一个预订系统,允许用户查看、编辑和删除记录。系统目前允许用户随时删除记录。但是,由于它是一个预订系统,因此用户只能在预订日期前48小时删除记录,并应限制用户在预订日期后24小时内删除记录。我是否需要包含某种函数

这是我删除记录的当前代码:

bookings.php

   echo "<td><a href = 'delete.php?id=".$row['booking_id']."' onclick='return          

   confirmation()'> Remove </td>"; 


      <script type="text/javascript">

        function confirmation()

  {

        if (confirm("Are you sure you want to cancel booking")){
             location.href='delete.php';

           }

           else {

            return false;


           }
         } 

我不知道您的表结构,但它应该是这样的:

DELETE from bookings1 where booking_id='$id' AND booking_id IN (SELECT booking_id FROM bookings1 
WHERE BookingDate >= DATEADD(HOUR, -48, GETDATE())
  AND BookingDate <  DATEADD(HOUR, -24, GETDATE())
也改变

location.href='delete.php'

location.href='delete.php?id=.$row['booking_id'];返回false


否则$\u GET为空

您可以将日期列添加到数据库中的记录中,然后在删除之前检查还有多少时间可以删除

$yourEntry = mysql_fetch_array(mysql_query("select * from bookings1 where booking_id='$id'"));


//Checking difference between two dates (current and your entry date)       
$diff = strtotime(date('Y-m-d H:i:s')) - strtotime(''.$yourEntry[day].' '.$yourEntry{hour].'');

//this is for less than 30 seconds, change for your value
                if($diff < 30){
                    $problem = TRUE;
                }



        if (!$problem){

//your code where there is not a problem with time. In my code if more than 30 seconds. 

         }

我的表结构是booking_id,BookingDate,TimeslotI我尝试过这种方法,但它不会从数据库中删除任何内容我的表由以下字段组成,即booking_id,BookingDate,timeslot@RohanRehman你的预订日期怎么样?它的日期是带时间的还是只带日期的?所以再添加一个带时间的字段。将日期设置为Y-m-d,时间设置为H:i:s。我的代码应该可以处理这个字段。如果我要删除statement@RohanRehman把它放在if$问题{//这里是您的代码}语句
$yourEntry = mysql_fetch_array(mysql_query("select * from bookings1 where booking_id='$id'"));


//Checking difference between two dates (current and your entry date)       
$diff = strtotime(date('Y-m-d H:i:s')) - strtotime(''.$yourEntry[day].' '.$yourEntry{hour].'');

//this is for less than 30 seconds, change for your value
                if($diff < 30){
                    $problem = TRUE;
                }



        if (!$problem){

//your code where there is not a problem with time. In my code if more than 30 seconds. 

         }