'How do I put massege when my record was deleted?
"When i delete my record form database by php it will directly delete. How can i display alert massage for deleted data"
if (isset($_GET['isDeleted']) && $_GET['isDeleted'] == '1') {
echo '
<div class="d-flex justify-content-center">
<div class="alert alert-success w-75" role="alert">
The employee data has been removed.
</div>
</div>
';
}
Solution 1:[1]
If you want to display the alert message in the frontend, the best practice is to check with session.
For example:
In you controller (or where you deleted your database record), add alert message like this:
$_SESSION["alert"] = [
'type' => 'deleted',
'title' => 'Deleted',
'message' => 'The employee data has been removed.',
];
- type is a css class name for style the alert.
Be sure you have started the session before:
session_start()
So, in the frontend (recommended in the header file), add a block like this:
if (isset($_SESSION['alert'])) {
echo '
<div class="d-flex justify-content-center ' . $_SESSION['alert']['type'] . '">
<h3>' . $_SESSION['alert']['title'] . '</h3>
<div class="alert alert-success w-75" role="alert">
' . $_SESSION['alert']['message'] . '
</div>
</div>
';
// remove the session, for display this alert just one time.
unset($_SESSION['alert']);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hamid Moladoust |
