SQL PHP会话删除系统

时间:2018-10-26 10:50:04

标签: php mysql

我制作了一个从sql检索数据的php表单。选择好并编辑好更新,但是我如何单击以删除此sql数据。我尝试了很多次,但也许出了点问题。请帮我提供这段代码

https://i.stack.imgur.com/U6T3k.jpg

<?php 
$sql = "SELECT * from tblclasses"; 
$query = $dbh->prepare($sql); 
$query->execute(); 
$results=$query->fetchAll(PDO::FETCH_OBJ); 
$cnt=1; 
if($query->rowCount() > 0) { 
   foreach($results as $result) { 
       ?> 
       <tr> <td><?php echo htmlentities($cnt);?></td> 
            <td><?php echo htmlentities($result->ClassName);?></td> 
            <td><?php echo htmlentities($result->CreationDate);?></td> 
            <td> <a href="edit-info.php?classid=<?php echo htmlentities($result->id);?>"><i class="fa fa-edit" title="Edit Record"></i> Edit</a> </td> 
       </tr> 
       <?php 
       $cnt=$cnt+1;
   }
} 
?>

1 个答案:

答案 0 :(得分:0)

使用删除链接在表中添加另一列:

<td> 
    <a href="delete-info.php?classid=<?php echo htmlentities($result->id);?>">
        <i class="fa fa-remove" title="Delete Record"></i> Delete
    </a> 
</td> 

创建delete-info.php。检查GET变量classid,然后进行DELETE查询!