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');

Answers:

Answer
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";
}
Answer

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.

Answer

you can do this:

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

on database.php

echo $_SESSION['msg'];
unset($_SESSION['msg']);
Answer

One solution is to put the message in a SESSION, in your php file. So in the original page, you get that SESSION variable, and display that. ex:

in your php file:

session_start();
$_SESSION["message"]="MESSAGE OF SUCCESS"

In you original file:

session_start();
    if(isset($_SESSION["message"]))
    {
        echo"SUCCESS OR THE MESSAGE SET IN THE VAR SESSION";
        unset($_SESSION["message"]);
    }
Answer

The best way to solve this problem is set a session message after the success of your operation in the process page. Then in the redirected page check whether the session message is set or not.If it is set then simply echo that message. The below code may help you.

 $_SESSION['MSG']="Your data is saved";
 Header( 'Location: Database.php');
 exit;
 //now in the database.php page write at the top
  <?php
   if(isset($_SESSION['MSG'])){
   echo $_SESSION['MSG'];
   }
  ?>//its very simple,you can also format the message  by using different html attributes
Answer

Before redirecting to new page, you can set a cookie with the message you want to show, upon loading the original page you will see if this special cookie is set and if it is you can display the success message stored in the cookie.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.