删除时的确认提醒

时间:2017-09-04 14:24:34

标签: javascript php ajax

我有一个带有删除<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;?>

1 个答案:

答案 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>";?>