2016-02-14 128 views
0

我需要为可以看到他预订的所有房间的一个用户取消预订房间。 问题是它显示用户的预订房间,但删除按钮无法正常工作。当我按下按钮时从MySQL表中删除行删除

我有我的db的快照here和屏幕截图here。请帮忙吗?

谢谢。

下面是节目的预约资料我的PHP代码,并在manage.php

<?php 

session_start(); 
$connection = mysqli_connect('localhost', 'root', '', 'webapp'); 

global $connection; 


$user_id=""; 
if(!isset($_SESSION['login_ID'])) { 
header('Location: login.php'); 
die(); 
} else { 
    $user_id= $_SESSION['login_ID']; 
} 


    $secondQueryStmt = "SELECT * FROM `booking` where UserID='".$user_id."'"; 
    $query = mysqli_query($connection, $secondQueryStmt); 

    if(isset($_POST['BookingID'])) { 
    $boking_id = $_POST['BookingID']; 
    if(isset($_POST['delete_id'])){ 




     $query = mysqli_query($connection, "DELETE FROM booking where BookingID= '".$boking_id."'"); 
    } 
} 

?> 这里是在同一个页面也是我的HTML表单中删除的部分。

<article id="content" style="height:810px; background-color:white"> 
     <div class="box1"> 
     <!--content herer--> 








        <table class="wrapper" style="text-align:center"> 
        <tr> 
        <th class="track animated fadeInUp">Room</th> 
        <th class="title animated fadeInUp">Quantity</th> 
        <th class="speaker animated fadeInUp">CheckIn Date</th> 
        <th class="day animated fadeInUp">CheckOut Date </th> 
        <th class="time animated fadeInUp"></th> 

        </tr> 
         <?php while($fetcher = mysqli_fetch_array($query)): ?> 
         <tr> 
         <td><?=$fetcher['Type']?></td> 
         <td><?=$fetcher['Quantity']?></td> 
         <td><?=$fetcher['CheckInDate']?></td> 
         <td><?=$fetcher['CheckOutDate']?></td> 
         <td><td><form action="manage.php" method= "post" /> 
        <input type="hidden" name="b_id" value="<?=$fetcher['BookingID'] ?>"/> 
        <input type="button" class="btnSm hvr-fade lightRed" name="delete_id" value="Cancel Booking"/> 
       </form></td></tr> 



       <?php endwhile; ?> 




     </table> 


     </div> 
    </article> 
+0

的DELETE后删除* - >从表 – sagi

+1

我不删除t看到任何开头'

',其次,你需要在选择t之前先删除数据,否则看起来好像数据没有被删除y即使它是。 – budirec

+1

执行SQL语句后应检查错误。还要了解准备好的陈述。 – Jens

回答

0

看看这里这个声明,

<input type="hidden" name="b_id" value="<?=$fetcher['BookingID'] ?>"/> 
          ^you've named it b_id, not BookingID 

因此改变

$boking_id = $_POST['BookingID']; 

$boking_id = $_POST['b_id']; 

并使用mysqli_affected_rows()功能检查多少行从受此影响UPDATE操作。

这里的参考:

所以,你的代码应该是这样的:

// your code 

$query = mysqli_query($connection, $secondQueryStmt); 

if(isset($_POST['delete_id'])){ 
    $boking_id = $_POST['b_id']; 
    mysqli_query($connection, "DELETE FROM booking where BookingID= '".$boking_id."'"); 
    if(mysqli_affected_rows($connection)){ 
     // success 
    }else{ 
     // failure 
    } 
} 
+0

感谢您的配合。我试过了,但同样的问题,按钮不工作。 –

+0

@BkrBaroudi这是因为你的输入'type'是'button',它阻止了表单被提交。将输入'type'更改为'submit',如下所示:'' –

+0

非常感谢,它现在可以在您的笔记和一些修改后生效。 我感谢您的帮助。 –