Hi all,
I'd like to show a message to the user if there has been any problem interacting with the database...
As an example, if I want to delete a record, but this record can't be deleted due to dependencies... I'd love showing a message to the user (something like a messagebox /alert).
The pages I'm working in are all generated by PHP.
The current structure is:
1. In page A I click a link (to delete a database record) that takes me to page B where the deletion code is.
2. In page B the deletion happens (call to the deleting function, check result) and jump back to page A.
What I've done by now works, but would like to know if there is a better way:
1. At the function fail (in page B) I set a session variable to the message I want to show:
if (deleteRecord()==FALSE) $_SESSION["myMessage"]="Deletion failed.";
2. At the page A I've written:
if ($_SESSION["myMessage"] != "")
{
$myMessage= addslashes($_SESSION["myMessage"]);
echo "<script type='text/javascript'>alert('$myMessage');</script>";
unset($_SESSION["myMessage"]);
}
Is there a better way to do this?
Thank you very much for your time and help.
What I have tried:
Searched the internet, tried to put a middle page with an onload event...