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";
?>
I would like to know how to pass variables from page to page
Moderator: General Moderators
-
Ron Austin
- Forum Newbie
- Posts: 1
- Joined: Mon Feb 06, 2012 9:54 pm
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: I would like to know how to pass variables from page to
Out of curiosity why do you have die(mysql_error()) in the code?
If you print_r($_SESSION) on the final page, what results (if any) do you get
Code: Select all
<?php
header("Location: http://www.xxx.com/twitter/write_a_tweet.php") or die(mysql_error());
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering