in index.php I have 3 buttons (add, delete, edit)
if I click to delete it will redirect to the delete page query (delete.php)
after delete success, the page redirects to index.php and the sweet alert2 will popup with a success message (deleted successfully)
if I add a user the msg will change to added successfully
it depends on where I redirect to index.php
so what I can do?
CodePudding user response:
Solution1
Before redirecting, you should create a session object and save the alert messages in sessions.
start_session()
$_SESSION["alert"] = ["type" => "success", "message" => "User deleted successfully"];
On index.php page
On a index.php page, check if there’s a flash/alert message. If so, output and delete it.
if (isset($_SESSION["alert"]))
{
echo
"<div class='alert alert-success alert-dismissible'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<h4><i class='icon fa fa-check'></i> Alert!</h4>
$_SESSION["alert"]
</div>";
unset($_SESSION["flash"]);
}
Thats it.
CodePudding user response:
While redirecting from delete.php/edit.php to index.php you can pass some query params.
Redirection from delete.php will look like index.php?msg="deleted successfully";
Redirection from edit.php will look like index.php?msg="added successfully"
In index.php you can read the query string msg and display the alert box
Here is the refs to get query string param.