-1

I have PHP page called index.php where I am displaying some data in table. 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

<?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. I want keep user on same page called index.php or want back on index.php after delete record. Let me know if someone can help me for do it. Sorry I am learning PHP and have not good knowledge of it. Thanks

Mira
  • 75
  • 1
  • 8

2 Answers2

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

Abhijit
  • 931
  • 1
  • 9
  • 21
0

You can redirect user to index.php at the end of delete.php by either using

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

OR using JS as below

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

Note: Replace http://localhost:8080/test/index.php with your URL.

Also a better option would be to use jQuery AJAX

Preeti
  • 152
  • 1
  • 8