I would like to know how to pass variables from page to page
Posted: Mon Feb 06, 2012 11:35 pm
I thought the code below should work, but I get no output. There are 4 pages; the first (not shown) gathers data
The second page examines the data and directs you to one of two other pages (depending upon the selections).
The last page acts on the data. The problem is that the data does not get passed to the last page.
Can someone please tell me what is wrong with this code?
//page 2
<?php
session_start();
$tweet_type=$_POST['tweet_type'];
$tweet=$_POST['tweet'];
$categ=$_POST['category'];
$_SESSION['category']=$_POST['category'];
$_SESSION['type']=$tweet_type;
$_SESSION['tweet']=$tweet;
$_SESSION['categ']=$categ;
if ($tweet_type=="write"){
header("Location: http://www.xxx.com/twitter/write_a_tweet.php") or die(mysql_error());
exit;
}
elseif ($tweet_type=="pick"){
header("Location: http://www.xxx.com/twitter/pick_a_tweet.php") or die(mysql_error());
exit;
}
?>
//last page
//http://www.xxx.com/twitter/pick_a_tweet.php
<?php
session_start();
$category=$_SESSION['category'];
$tweet_type=$_SESSION['type'];
$tweet=$_SESSION['tweet'];
$categ=$_SESSION['categ'];
echo "category $category<br>";
echo "type $tweet_type<br>";
echo "tweet $tweet<br>";
echo "categ $categ<br>";
echo "PICK A TWEET";
?>
The second page examines the data and directs you to one of two other pages (depending upon the selections).
The last page acts on the data. The problem is that the data does not get passed to the last page.
Can someone please tell me what is wrong with this code?
//page 2
<?php
session_start();
$tweet_type=$_POST['tweet_type'];
$tweet=$_POST['tweet'];
$categ=$_POST['category'];
$_SESSION['category']=$_POST['category'];
$_SESSION['type']=$tweet_type;
$_SESSION['tweet']=$tweet;
$_SESSION['categ']=$categ;
if ($tweet_type=="write"){
header("Location: http://www.xxx.com/twitter/write_a_tweet.php") or die(mysql_error());
exit;
}
elseif ($tweet_type=="pick"){
header("Location: http://www.xxx.com/twitter/pick_a_tweet.php") or die(mysql_error());
exit;
}
?>
//last page
//http://www.xxx.com/twitter/pick_a_tweet.php
<?php
session_start();
$category=$_SESSION['category'];
$tweet_type=$_SESSION['type'];
$tweet=$_SESSION['tweet'];
$categ=$_SESSION['categ'];
echo "category $category<br>";
echo "type $tweet_type<br>";
echo "tweet $tweet<br>";
echo "categ $categ<br>";
echo "PICK A TWEET";
?>