Jump to content

Redirect echo help


99daocon

Recommended Posts

I am new to PHP and I am a bit confused. I know its an easy solution but I can't get my head around it.

 

I have a form which is to send a message to a database.

After the form is sent it redirects you to another page.

This works fine, but I want it to give you some feedback, so basically say that your message has successfully been posted.

Here is my PHP:

 

form.php

 

<?php

function posted(){

global $redirect;

include 'formindb.php';

if $redirect = true;{

echo "Your message has been posted";

}

}

?>

 

formindb.php

 

$redirect = header("Location: form.php");

Link to comment
https://forums.phpfreaks.com/topic/91979-redirect-echo-help/
Share on other sites

Ok so I put this at the end of my php file which sends the form to the database

 

<meta http-equiv="Refresh" content="5; url=/CMS/TEST/form.php">

 

The page says that your message has succesfully been posted then redirects back to the form, but thats not really what I wanted.

It will do though.

 

I would have prefered setting the redirect as a variable, which is true when redirected, and false when not.

So I would include the variable on the other page and if it is true it would echo your message has been posted, if false it wouldnt do anything. Is that possible?

Link to comment
https://forums.phpfreaks.com/topic/91979-redirect-echo-help/#findComment-471079
Share on other sites

Sessions are just another variable.

 

On success, just set $_SESSION['success'] = "yes";

 

On your other page, just read  $_SESSION['success'] to see if it == "yes"

 

Make sure you use session_start(); at the top of each page that uses sessions.

Link to comment
https://forums.phpfreaks.com/topic/91979-redirect-echo-help/#findComment-471105
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.