Jump to content

Recommended Posts

Hello all,

I've got a script that, it seems to me should work fine but, alas, it does not. I simply want to change a session variable for a page based on whether or not a form on that page has been submitted. The session variable "page" does nothing more than populate text. Here it is...

<?php
session_start();
if($submit) {
$_SESSION['page'] = "Thank You!";
include "/header.php";
//RESULT OF SUBMITTED FORM HERE
include "/footer.php";
}
else {
$_SESSION['page'] = "Send Us Your Event";
include "/header.php";
//PAGE WITH FORM HERE
include "/footer.php";
}
?>

 

The result of this script is I keep getting the form page...no submission and the "page" var stays the same.

However, If I break up the session variable declarations and the 2 pages into 2 different IF statements, both requiring the submit var, the form will submit but, once again, the session variable remains the same.

 

Any suggestions?

 

 

Where does $submit come from? Is this the name of your submit button? If it is it should be $_POST['submit'] or $_GET['submit'] depending on your forms submit method (this is defined in the form tag).

 

<?php
session_start();

include "./header.php";

if(isset($_POST['submit']))
{
$_SESSION['page'] = "Thank You!";

//RESULT OF SUBMITTED FORM HERE

}
else {
$_SESSION['page'] = "Send Us Your Event";

//PAGE WITH FORM HERE
}

include "./footer.php";
?>

You'll only know if you test it. I don't know what you doing. I just assumed $submit variable refers to your form's submit button, make sure you have a submit button in your form named submit in order for the if/else statement to work.

 

The problem is to do with the argument in your if statement. Not to do with your session variables.

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.