Echo some text on php page when successfully registered

Hi all, I have a similar thread shown below but I feel that this is a different question now.

(Echo Some text on page reload from die)

I have a register page where a user enters their details and I have included this on index.php

When the user registers using this form, I have a header taking them back to the index page (as before this it would just show the register.php file on screen and not the index stuff)

I would like to display a message that says that they have successfully registered when they hit the button but I want this message to be on the index page.

Any advice on this would be appreciated, I am a total amateur so idiot proof language would be appreciated.

Thanks

A

One way to do that would be to set a session variable in the page that processes the registration, then modify the index page to check the session variable and display the message if it finds it. So in your registration code you would do something like

$_SESSION['msg'] = "Registration was successful";
// then redirect however you do that

and in the index page

if (isset($_SESSION['msg'])) { 
  echo $_SESSION['msg']; // might need this in a specific place on the page, a div or whatever
  $_SESSION['msg'] = "";
  }

Read up on sessions - you need to ensure that you call session_start() before you do any page output.

1 Like

Thats magic, thanks so much for your help.

Yes I am seeing more and more that I need to learn more about sessions.

Thanks Again

Adam

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.