99daocon Posted February 19, 2008 Share Posted February 19, 2008 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"); Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 You can't really use a header after output, so you would use a HTML redirect instead. Quote Link to comment Share on other sites More sharing options...
99daocon Posted February 19, 2008 Author Share Posted February 19, 2008 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? Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Sure, you can use a session for that or put a setting in a URL like mypage.php?success=yes Then on your other page, use $_GET['success'], and if yes echo something, if empty or no, do something else. Quote Link to comment Share on other sites More sharing options...
99daocon Posted February 19, 2008 Author Share Posted February 19, 2008 Any examples? I have a basic understanding of session but I am confused as to how it would work in this situation. Sorry for being a pain. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 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. Quote Link to comment Share on other sites More sharing options...
99daocon Posted February 19, 2008 Author Share Posted February 19, 2008 Awesome, many thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.