简体   繁体   English

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

[英]Stay on Same Page or Redirect Old Page after Delete Action

I have PHP page called index.php where I am displaying some data in table.我有一个名为 index.php 的 PHP 页面,我在表中显示了一些数据。 I have action button called Delete from where user can delete record from table like below我有一个名为“删除”的操作按钮,用户可以从中删除表中的记录,如下所示

<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>

My delete.php is like below我的 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();
?>

Its opening new page called delete.php and stay on same page after record get delete.它打开名为delete.php 的新页面并在记录被删除后保持在同一页面上。 I want keep user on same page called index.php or want back on index.php after delete record.我希望将用户保留在名为 index.php 的同一页面上,或者在删除记录后返回 index.php。 Let me know if someone can help me for do it.如果有人可以帮助我做到这一点,请告诉我。 Sorry I am learning PHP and have not good knowledge of it.对不起,我正在学习 PHP 并且对它没有很好的了解。 Thanks谢谢

 <?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();


    ?>

You just redirect again index.php page您只需再次重定向 index.php 页面

You can redirect user to index.php at the end of delete.php by either using您可以使用以下任一方法将用户重定向到 delete.php 末尾的 index.php

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

OR using JS as below或使用 JS 如下

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

Note: Replace http://localhost:8080/test/index.php with your URL.注意:将http://localhost:8080/test/index.php替换为您的 URL。

Also a better option would be to use jQuery AJAX还有一个更好的选择是使用 jQuery AJAX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM