I have two pages: index.php
and stats.php
Both of the pages contains the same query from database, and have a delete button. When pressing the delete-button
it redirect like this: https://example.com/delete.php?id=50;
where 50 is the row ID.
The delete.php
looks like this:
<?php
include "db.php"; // Using database connection file here
$id = $_GET['id']; // get id through query string
$del = mysqli_query($link,"DELETE FROM table WHERE id = '$id'"); // delete query
if($del)
{
mysqli_close($link); // Close connection
header("location:index.php"); // redirects to all records page
exit;
}
else
{
echo "Error deleting record"; // display error message if not delete
}
?>
The problem now is that when the user press delete, it deletes the row, and redirects back to index.php. But how can I check what page it was deleted from, and redirect back to that page?
EDIT:
For testing purpose, I tried something like this below, but when deleting from both pages, both of them gave me the same output: "2":
if($del)
{
if($_SERVER['HTTP_REFERER'] == "index.php")
{
echo "1";
} else {
echo "2";
}
}