2015-06-09 20 views
-1

我有一張表,每行都有一個取消鏈接。我想取消特定行的預訂。我可以知道如何開始? 表格的代碼如下。如何使用php和mysql取消特定行的預訂

$result = mysqli_query($con, $sql); 
    if (mysqli_num_rows($result) > 0) { 
     echo "<table border = 1> 
     <tr> 
       <th>Custid</th> 
       <th>Venue</th> 
       <th>Firt Name</th> 
       <th>Date</th> 
       <th>Time</th> 
       <th>Menu Type </th> 
       <th>No.of table </th> 
       <th>Total price </th> 
       <th>Amount Paid </th> 
       <th>Make Payment </th> 
       <th>Cancel Booking</th> 
     </tr>"; 
     while($row = mysqli_fetch_assoc($result)) { 
       echo "<tr>"; 
        echo "<td>" . $row['Customer_id']. " </td>"; 
        echo "<td>" . $row['Venue_name']. " </td>"; 
        echo "<td>" . $row['First_name']. "</td>"; 
        echo "<td>" . $row['Date']. "</td>"; 
        echo "<td>" . $row['Time']. "</td>"; 
        echo "<td>" . $row['Menu_type']. "</td>"; 
        echo "<td>" . $row['no_of_table']. "</td>"; 
        echo "<td>" . $row['total_price']. "</td>"; 
        echo "<td>" . $row['total_amt_paid']. "</td>"; 
        echo"<td><a href='Payment.php'>Payment</a></td>"; 
        echo"<td><a href='Cancel.php'>Cancel</a></td>"; 
       echo "</tr>"; 
     } 

     echo "</table>";        

    } 
+0

你可以添加到cancel.php調用可能與URL querystring的ID。 – Goikiu

+1

'href =「cancel.php?$ row [id]」'或其他... –

+0

對於「Payment」和「Cancel」,您至少需要一個「ID」來識別您的行。 – Alex

回答

1

您需要通過Cancel.php腳本應該刪除的內容有一定的瞭解,所以更改

echo "<td><a href='Cancel.php'>Cancel</a></td>"; 

echo '<td><a href="Cancel.php?Customer_id=' . $row['Customer_id'] . '">Payment</a></td>'; 

然後在Cancel.php腳本,你應該會收到價值在$ _GET數組中

<?php 

    $Customer_id = $_GET['Customer_id']; 
+0

嗨,感謝您的幫助。我會嘗試與您的建議 –

0

如果您想要取消特定預訂,您需要針對每項預訂的具體內容,例如預訂ID。如果我們假設你已經在你的表中有這個,那麼你可以將這個唯一的值(特定的行)傳遞給你的cancel.php和payment.php頁面。

爲此,我們將使用get請求和查詢字符串。這將意味着您的原始行更改如下:

echo "<td><a href='Cancel.php'>Cancel</a></td>"; 

下面這一個。我們可以添加查詢字符串唯一的這樣的每一行:(假設它可能被稱爲booking_id

echo "<td><a href='Cancel.php?booking_id=".$row['booking_id']."'>Cancel</a></td>"; 

現在,您可以檢索這樣的Cancel.php頁面上此值:

$booking_id = $_GET['booking_id']; 

值得關注SQL injection,並考慮爲您的字符串添加一些清潔方法以避免這種情況。如果你在GET和POST上有點生鏽,那麼你可以檢查this explanation

+0

嗨安迪我會嘗試與您的建議 –

+0

嗨安迪,是的,我使用booking_id刪除。是我檢索$ booking_id = $ _GET ['booking_id']的值;並可以刪除這個選擇的值? –

+0

'$ _GET ['booking_id']'保存通過Cancel.php?booking_id傳遞的值。所以,如果你按照這樣的鏈接:'Cancel.php?booking_id = 2',那麼'$ _GET ['booking_id']'將是2.爲了刪除,你需要使用一個查詢來刪除WHERE booking_id是等於'$ booking_id' – Henders

相關問題