2016-09-29 47 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