2016-09-29 72 views
-2

我的代碼有什麼問題?刪除表格的行代碼

我的PHP正在工作,但刪除按鈕不起作用!

if(isset($_POST['delete'])) { 
       $ID = $_POST['value']; 
       $delete = "DELETE FROM tbl_document WHERE ID = $ID"; 
       $result = mysqli_query($con,$delete); 
      } 
      $query = "SELECT * FROM tbl_document LIMIT $start, $end"; 
      $result = mysqli_query($con,$query); 
      echo "<table border='1' width='300' height='160' align = center id='result'>"; 
      echo '<tr> 
        <th width="80">ID</th> 
        <th width="200">Title</th> 
        <th width="260">Presented To</th> 
        <th width="260">Presented By</th> 
        <th width="160">Date Submitted</th> 
        <th>Location</th> 
        <th width="17%">Option</th> 
       </tr>'; 
      while($row = mysqli_fetch_array($result)){ 
echo "<tr align = center >"; 
       <td width='20' height='60'>" .$row['ID']. "</td>"; 
       <td width='120' height='60'>" .$row['Title']. "</td>"; 
       <td>" .$row['Presented_To']. "</td>"; 
       <td>" .$row['Presented_By']. "</td>"; 
       <td>" .$row['Date_Submitted']. "</td>"; 
       <td>" .$row['Location']. "</td>"; 
"<td width='17%'>"; 
       ?> 
       <?php if($_SESSION['user'] == "1") 
       ?> 
<button class="w3-btn w3-red w3-border-large w3-circle" value="<?php echo $row['ID'];?>" name="delete" style="width:40%"><i class="fa fa-trash-o"></i>Delete</button> 
       <?php } ?> 
       <?php 
       echo "</td>"; 
      echo "</tr>"; 
      } 
      echo"</table>"; 
+4

的一個大問題 - 這似乎是100%的失蹤了! Pesky代碼不能保持不變... –

+0

請發佈您的代碼,我想你忘了它。 – Arendax

+0

代碼請!!!! –

回答

0

一個button是不夠的發送數據,則需要一個form中包含它。

這是應該的樣子:

<form method="post"> 
    <button name="delete" value="<?php echo $row['ID'];?>" class="w3-btn w3-red w3-border-large w3-circle" style="width:40%"><i class="fa fa-trash-o"></i>Delete</button> 
</form> 
+0

它可以工作,但$ ID = $ _POST ['value'];是undefined – Leira

+0

這應該是:'$ ID = $ _POST ['delete'];' – Aziz

+0

謝謝先生! – Leira