我有一个带有删除<a>
标记的表格。我已经可以删除数据了。但是,如果用户想要真正删除它,我想做的是提出是或否。我尝试使用JavaScript,但我无法使其正常运行。
这是我的代码
<?php
$action = '';
if(isset($_GET['action']))
$action=$_GET['action'];
if($action=='delete')
{
$speakerid=$_GET['speakerid'];
$delete = mysqli_query($conn, "DELETE FROM accounts WHERE id=$speakerid");
header("Location:accountList.php");
}
?>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['lastname'];?></td>
<td><?php echo $row['emailaddress'];?></td>
<td><?php echo $row['contactnumber'];?></td>
<td><?php echo $row['status'];?></td>
<td><?php echo $row['date_added'];?></td>
<td align='center'><?php echo "<a style='padding:6px; background-color:red; color:white; border-radius: 3px;' href='accountList.php?action=delete&speakerid=".$row['id']."'>delete</a>";?></td>
</tr>
<?php endwhile;?>
答案 0 :(得分:1)
一种简单的方法是:
<?php echo "<a style='padding:6px; background-color:red; color:white; border-radius: 3px;' href='accountList.php?action=delete&speakerid=".$row['id']."' onclick='return confirm(\"Really delete ?\");'>delete</a>";?>