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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.