删除操作后留在同一页面上或重定向旧页面

时间:2018-11-13 06:42:54

标签: php mysqli

我有一个名为index.php的PHP页面,其中在表中显示了一些数据。我有一个名为“删除”的操作按钮,用户可以从中删除下表中的记录

<td><center><a href="delete.php?id=<?php echo $apl_installations_row['installation_id'];?>">
                                        <i class="fas fa-times"style="color:red"></i>
                                    </a></center></td>

我的delete.php如下所示

<?php 
session_start();
include_once "../sessioncheck.php";
include_once "config.php";
$user_id = $_SESSION['id'];
$id = (int)$_GET['id'];

$update = $con->prepare("DELETE FROM apl_installations WHERE installation_id = ? AND client_id = ?");
$update->bind_param('ii', $id, $user_id);
$update->execute();
$update->close();
?>

它会打开一个名为delete.php的新页面,并在记录被删除后保留在同一页面上。我想让用户保持在名为index.php的同一页面上,或者想在删除记录后返回index.php。 让我知道是否有人可以帮助我。抱歉,我正在学习PHP,但对PHP并不了解。 谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用

将用户重定向到delete.php末尾的index.php。

header("Location: http://localhost:8080/test/index.php");

或如下所述使用JS

<script>window.location.href = "http://localhost:8080/test/index.php";</script>

注意:用您的网址替换http://localhost:8080/test/index.php

另外一个更好的选择是使用jQuery AJAX

答案 1 :(得分:0)

 <?php 
    session_start();
    include_once "../sessioncheck.php";
    include_once "config.php";
    $user_id = $_SESSION['id'];
    $id = (int)$_GET['id'];

    $update = $con->prepare("DELETE FROM apl_installations WHERE installation_id = ? AND client_id = ?");
    $update->bind_param('ii', $id, $user_id);
    $update->execute();
    $update->close();
    header("Location: http://example.com/index.php");
    die();


    ?>

您只需再次重定向index.php页面

相关问题