Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

displaying a message after redirecting the user to another web page

I am doing HTML with PHP and MySql. After some database operation that was performed by the user, my system redirects the user to the original database page in order to show him the updated table. (I am done with this part). At the same time, I wish to display a message to the user on the original page (the one where the system moved) to notify him with the success of the operation. How can I possibly display this message?

Here's my php code that moves to the other page.

Header( 'Location: Database.php');
like image 534
Traveling Salesman Avatar asked Sep 03 '12 14:09

Traveling Salesman


3 Answers

Header( 'Location: Database.php?success=1' );

And in the Database.php page :

if ( isset($_GET['success']) && $_GET['success'] == 1 )
{
     // treat the succes case ex:
     echo "Success";
}
like image 72
Cosmin Avatar answered Oct 11 '22 07:10

Cosmin


Store it in the session as sort of a "flash"-message:

$_SESSION['message'] = 'success';

and show it in Database.php after the redirect. Also delete its content after displaying it:

print $_SESSION['message'];
$_SESSION['message'] = null;

The advantage of this is, that the message won't be shown again every time the user refreshes the page.

like image 38
insertusernamehere Avatar answered Oct 11 '22 08:10

insertusernamehere


you can do this:

$_SESSION['msg']="Updation successfully completed";
header("location:database.php");

on database.php

echo $_SESSION['msg'];
unset($_SESSION['msg']);
like image 34
Harshal Mahajan Avatar answered Oct 11 '22 08:10

Harshal Mahajan