删除按钮不起作用,返回空白页

时间:2017-04-06 08:26:14

标签: php html

我的删除按钮无效。

对于视图文件,它正在运行 - 这是我的代码 view_file.php



<?php
$sql_id="SELECT * FROM meeting_info where id=".$id ;
`$result2 = $conn->query($sql_id);
if($row2 = $result2->fetch_assoc()) {
$bilno = $row2['bilno'];
}
?>

  <body>
    <div id="body">
      <table align="center" width="90%">
        <tr>
          <th colspan="6">
            <div align="center">
              <h3>Meeting Bil.No
                <?php echo $bilno; ?> </h3>
            </div>
          </th>
        </tr>
        <tr bgcolor="#3366ff">
          <td>Bil. Item</td>
          <td>File Type</td>
          <td>File Size (KB)</td>
          <td>View</td>
          <td>Edit</td>
          <td>Delete</td>
        </tr>
        <?php
$sql="SELECT * FROM meeting_details where id=".$id ." order by item_no asc";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) 
{
    if($j%2 == 1) {$colortd = "#99ccff";
}
	else 	{$colortd = "#f5f5f0";}   
?>
          <tr bgcolor=<?php echo $colortd;?>>
            <td>
              <?php echo $row['item_no'] ?>
            </td>
            <td>
              <?php echo $row['type'] ?>
            </td>
            <td>
              <?php echo $row['size'] ?>
            </td>
            <td>
              <a class="btn btn-view" href="uploads/<?php echo $row['file']; ?>" target="_blank" alt="<?php echo $row['item_no']; ?>" title="click for edit">
                <center><img src="images\iconview.png"></center>
              </a>
            </td>
            <td>
              <a class="btn btn-info" href="edit_file.php?edit=<?php echo $row['id']; ?>" title="click for edit" onclick="return confirm('sure to edit ?')">
                <center><img src="images\iconedit.png"></center>
            </td>
            <td>
              <a class="btn btn-danger" href="delete_file.php?delete=<?php echo $row['id']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')">
                <center><img src="images\icondel.png"></center>
            </td>

          </tr>
          <?php
		$j++;
 }
 //$conn->close();
 ?>
      </table>
    </div>
  </body>
&#13;
&#13;
&#13;

对于删除按钮,我想删除我要删除的信息的所有行。但它不起作用。当我点击删除按钮时,它就会弹出空白页面。数据仍然存在于数据库和网站中。

这是我的 delete_file.php 代码:

&#13;
&#13;
<?php 
  include("db_conn.php");  
if (isset($_GET['id']) && is_numeric($_GET['id']))
{  
	$id =$_GET['id']; 
	$sql = "DELETE FROM meeting_details WHERE id=".$id; 
	$result = $conn->query($sql);
	
}
$conn->close();
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

检查此行:

<a class="btn btn-danger" href="delete_file.php?delete=<?php echo $row['id']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')">

这里的删除网址类似于:delete_file.php?delete=1,您正在获取值:

$id =$_GET['id'];

所以改成它:

$id =$_GET['delete']; 

再试一次。

注意:您的代码对SQL注入是开放的