Jump to content

Sessions and passing variables


dazz_club
Go to solution Solved by teamatomic,

Recommended Posts

Hello,

 

I'm creating a questionnaire to try and get better at understanding sessions but I've stupidly fallen at the first hurdle.

 

My problem is that I can't successfully pass variables from one page to another. You see, I'm trying to split my questionnaire into smaller questions, rather than having really long list of questions.

 

Here is what the php code in my first page looks like;

 

session_start();
$_SESSION['contact_us'] = $contact_us;
$_SESSION['response_time_email'] = $response_time_email;

//checks to see if form is submitted and a question (tick box) has been checked
if(isset($_POST['submitted'])) {
if(!isset($_POST['contact_us'])) {

                //if check box empty display
	$must_complete = "<div id=\"fail\"><p>Please select a contact method; <strong>email, tel, fax or post</strong></p></div> ";

}else{
                 //if checked take them to the next page
	if(isset($_POST['contact_us'])){

	//$confirm = 'yes '.$contact_us.'';
	header('Location:page2.php');
	}
}
}

 

the two variables $contact_us and $response_time_email are there to store the variables and then pass them to the next page.

 

Here is the php code in my second page, that receives it

 

session_start();
$contact_us = $_POST['contact_us'];
$response_time_email =  $_POST['response_time_email'];

//if previous button is submitted go to previous page
if(isset($_POST['previous'])) {

header('Location:index.php');

}

 

I think I could have it all mixed up here. If anyone can point in the right direction I would be grateful.

 

Many thanks

Link to comment
Share on other sites

  • Solution

In your first page you set the session vars, good. In your next page you convert POST to $contact_us. Bad, if you want what was in the session var. On your second page you need to do the reverse of the first page:

$contact_us=$_SESSION['contact_us'];

instead of using POST, that is just for posted form data.

 

 

HTH

Teamatomic

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.