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

时间:2015-03-08 15:33:20

标签: php mysql

我目前有一个预订系统,允许用户查看,编辑和删除记录。系统目前允许用户随时删除记录。但由于这是一个预订系统,因此用户应该只能在预订日期前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.php 

          $id = $_GET['id'];

             $query1="DELETE from bookings1 where booking_id='$id'";

                  $results = $mysqli->query($query1);

2 个答案:

答案 0 :(得分:0)

我不知道你的桌面结构,但它应该是这样的:

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']."'; return false;

否则$ _GET为空

答案 1 :(得分:0)

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

$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. 

         }