Problems with transfering variables from page to page

Hello, I am having problems with my code. Its supose to on the first page display the query, Then once its displayed it has a link on the Name that was pulled from the database linking to the next page thats supose
to pull the info from what I clicked on on the first page. The code bellow is set to only display the name on the second page, because once thats working i can fill the rest in. Right now it only displays the info on the first page. The linked name takes it to the next page but doesnt display any info. Hope this helps:
First page:

1, John Hancock 2010:11:10 12:30:00 131-555-2121

Second Page:
Name: John Hancock
Address: 1212 main st
City: Hank State: DC

connect.php just has the database info.
First Page: Index.php
[php] ?php
// session_start();
$_SESSION[‘id’] = $_POST;

//echo $_SESSION[‘id’];
$_POST[‘id’];
$customerid = trim(stripslashes($_POST[‘customerid’]));
//$id = $_POST[‘id’];
//session_start();
//echo "Your logged in as ".$_SESSION[‘user’];
include ‘connect.php’;
$query=“SELECT * FROM worksheets WHERE status = ‘1’ AND priority != 1”;
// $query=“SELECT * FROM worksheets”;
$result=mysql_query($query);
$num=mysql_numrows($result);
print ‘

’;
print "";
for ($i=0; $i<$num; $i++) {
print “”;
print ‘
In Shop: $num
’;
$id=mysql_result($result,$i,“id”);
$name=mysql_result($result,$i,“name”);
$date=mysql_result($result,$i,“date”);
$time=mysql_result($result,$i,“time”);
$phone=mysql_result($result,$i,“phone”);
$page= “results.php”;
echo “$id, $name, $date, $time, $phone
”;
}
$worksheetnum = trim(stripslashes($_POST[‘worksheetnum’]));
$customerid = trim(stripslashes($_POST[‘customerid’]));
$id = $_POST[‘wo’];
print $worksheetnum;
?>
[/php]

Second Page: results.php
[php]
?php
//session_start();
include ‘connect.php’;
$_SESSION[‘id’] = $_POST;
echo $_SESSION[‘id’];
$customerid = trim(stripslashes($_POST[‘customerid’]));
$id = $_POST[‘id’];
//Get Worksheet ID data from database

	$query="SELECT *  FROM `worksheets` WHERE `id` = $id";

$result=mysql_query($query);
$num=mysql_numrows($result);

$n=0;
while ($n < $num) {
$customerid=mysql_result($result,$i,“customer”);
$worksheetnum=mysql_result($result,$i,“worksheet”);
$techid=mysql_result($result,$i,“inshop”);
$n++;
};

//Get Customer Data from datebase from $customerid
$query=“SELECT * FROM worksheets WHERE id = $customerid”;
//$query=“SELECT * FROM worksheets WHERE id = $customerid”;
$result=mysql_query($query);
$num=mysql_numrows($result);

$n=0;
while ($n < $num) {
$name=mysql_result($result,$i,“name”);
$phone=mysql_result($result,$i,“phone”);
$alt=mysql_result($result,$i,“alt”);
$address=mysql_result($result,$i,“address”);
$city=mysql_result($result,$i,“city”);
$state=mysql_result($result,$i,“state”);
$zip=mysql_result($result,$i,“zip”);
$n++;
};
[/php]

you are setting $customerid with the following on 1st page (index) :
$customerid = trim(stripslashes($_POST[‘customerid’]));

Where are you getting this value on the first page does this come from a page before index? If so, is it being set properly?

You could print_r($_POST) to see what data you are getting on page 2.

on results.php you are have two while loops using $n, then within the while loops you use $i, try changing $i to $n.

the parts with the error:
[php]
$n=0;
while ($n < $num) {
$customerid=mysql_result($result,$i,“customer”);
$worksheetnum=mysql_result($result,$i,“worksheet”);
$techid=mysql_result($result,$i,“inshop”);
$n++;
};

//Get Customer Data from datebase from $customerid
$query=“SELECT * FROM worksheets WHERE id = $customerid”;
//$query=“SELECT * FROM worksheets WHERE id = $customerid”;
$result=mysql_query($query);
$num=mysql_numrows($result);

$n=0;
while ($n < $num) {
$name=mysql_result($result,$i,“name”);
$phone=mysql_result($result,$i,“phone”);
$alt=mysql_result($result,$i,“alt”);
$address=mysql_result($result,$i,“address”);
$city=mysql_result($result,$i,“city”);
$state=mysql_result($result,$i,“state”);
$zip=mysql_result($result,$i,“zip”);
$n++;
};
[/php]

It just says
Array( ) when i do:
print_r($_POST);
With the code on the 2nd page and using first page to get there.
So this means its not sending any data to the second?
If thats so then what am I doing wrong, I thought the session would take care of it.

Are you getting a valid value for the $customerid = trim(stripslashes($_POST[‘customerid’])); in index?

sorry didnt mean to post that remove the:
print “<input type=“hidden” name=“worksheetnum” value=$worksheetnum>”;
print “<input type=“hidden” name=“customerid” value=$customerid>”;
print “<input type=“hidden” name=“wo” value=$id>”;
and
$customerid = trim(stripslashes($_POST[‘customerid’]));
Those are no longer used, it used to be displayed by a button and now we want it by link so these arent used now.

If you are getting the value from a link you are using the wrong method. you should be using _GET not _POST

ok let me explain more
1 its getting stuff from the database and displaying it
2. The results are clickable via link
3. it posts the results of the link to the other page.

how are you posting the link from index to the second page? are you using a form for this?

why not make the links on index like this

newpage.php?val1=somthing&val2=something else

and then in page 2 you would use the _GET

It might help us all if you just posted the index code and the send page code for review.

OK I found a problem and now it works with:
blabla.com/results.php?id=1
and propery displays all the information about id 1
Now, How do I get (code bellow) to open up ?id=$id
This code doesnt work for some reason:
[php]
$page= “results.php?$id”;
echo “$id, $name, $date, $time, $phone
”;
[/php]

sorry I didnt find a way to edit my last post:

I figured it out, Its working great now, Thanks all for the help!
Problem Solved.

Sponsor our Newsletter | Privacy Policy | Terms of Service