Passing Variables from an html form through three php pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dschuckman
Forum Newbie
Posts: 5
Joined: Tue Sep 02, 2003 3:59 pm

Passing Variables from an html form through three php pages

Post by dschuckman »

Hello

I am trying to pass information that is submitted on a html generated form through three php pages and then submit the information into a mysql database.

I am able to capture the information in the first php page with \
<?php $variable = $_POST['passed_variable'] ?>

but I dont know how to pass to the next page. Any help would be greatly appreciated.

David
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

why do you need to pass through 3 php pages?

how are you redirecting to each page?
dschuckman
Forum Newbie
Posts: 5
Joined: Tue Sep 02, 2003 3:59 pm

Post by dschuckman »

Whats happening is I have designed a bandwidth testing page. And the members have to fill out a form before they start. There are three pages that occur through out the testing then it finally submits all results and the information entered by the user to a mysql database.

If i were using perl I would just include a bunch of hidden tags as I went through.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

umm.. if you're using php, and it can only remember what it picks up on each page, and perl is the same way, why not use the same solution?

you can't grab variables that aren't there, likewise you can't remember upon a pageload what's not there.

you have two things that you can do
1: put them into hidden variables (post or get)
2: put them into cookies


well there is always just making it one page
dschuckman
Forum Newbie
Posts: 5
Joined: Tue Sep 02, 2003 3:59 pm

Post by dschuckman »

How do I pass them with posts and gets beyond the first page?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

to make a form automatically submit, put this javascript at the end of your page (before the </body> tag

Code: Select all

<script language="javascript">
    form1.submit();
</script>
don't forget to change form1 to the name of YOUR form.

Mark
Last edited by JayBird on Wed Sep 03, 2003 5:29 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

How do I pass them with posts and gets beyond the first page?
You need a bit of script that picks up the posted variables and puts them into hidden inputs within the form.

Mac
dschuckman
Forum Newbie
Posts: 5
Joined: Tue Sep 02, 2003 3:59 pm

Post by dschuckman »

<?php include_once("config.inc.php"); ?>

<html>
<head>
<title><?php echo $isp_name; ?> - Bandwidth Meter</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META HTTP-EQUIV="Expires" CONTENT="Fri, Jun 12 1981 08:20:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<link rel="stylesheet" href="style.css">
</head>

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0">
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><?php echo $header; ?></td>
</tr>
</table>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td><br><br><br><br><br><br><font size=+1>
Conducting bandwidth tests...
</font></td>

</tr>
</table>

<script>
<!--
time = new Date();
starttime = time.getTime();
// -->
</script>

<?php
$data_file = "payload.bin";
$fd = fopen ($data_file, "rb");
if (isset($_GET['kbps'])) {
$test_kbytes = ($_GET['kbps'] / 8) * 10; //set the download to take 10 seconds
if ($test_kbytes > 3000) {
$test_kbytes = 3000;
}
} else {
$test_kbytes = $default_kbyte_test_size;
}
$bob = $_POST['customer'];
$contents = fread ($fd, $test_kbytes * 1024);

echo "<!-- $contents -->";
fclose ($fd);

?>



<script>
<!--
time = new Date();
endtime = time.getTime();
if (endtime == starttime)
{downloadtime = 0
}
else
{downloadtime = (endtime - starttime)/1000;
}

kbytes_of_data = <?php echo $test_kbytes; ?>;
linespeed = kbytes_of_data/downloadtime;
kbps = (Math.round((linespeed*8)*10*1.024))/10;

<?php
$nexturl = "results.php?kbps=' + kbps + '&downloadtime=' + downloadtime + '&KB=' + kbytes_of_data + '&recorded=1";
?>


nextpage='<?php echo $nexturl; ?>';
document.location.href=nextpage
// -->
</script>
<center>
<form name="form1"action="http://192.168.1.126/intranet/bandwidth ... esults.php" method="POST">
<input type = "hidden" name = "customer" value = "<?php echo $customer = $_POST['customer']; ?>"><?php echo $customer; ?>
nextpage='<?php echo $nexturl; ?>';
</form>
<script language="javascript">
form1.submit();
</script>
</body>
</html>


here is the actual script any thoughts on passing both the cuncatination and the hidden items?
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

somethin like this.. if you are passing arrays those will have to be broken out as well..

Code: Select all

foreach ($_POST as $key => $val)&#123;
    print"<input type="hidden" name="&#123;$key&#125;" value="&#123;$val&#125;">";
&#125;
dschuckman
Forum Newbie
Posts: 5
Joined: Tue Sep 02, 2003 3:59 pm

Post by dschuckman »

Does it look like I am getting any closer?



<script>
<!--
time = new Date();
endtime = time.getTime();
if (endtime == starttime)
{downloadtime = 0
}
else
{downloadtime = (endtime - starttime)/1000;
}

kbytes_of_data = <?php echo $test_kbytes; ?>;
linespeed = kbytes_of_data/downloadtime;
kbps = (Math.round((linespeed*8)*10*1.024))/10;

<?php echo $kbps = "kbps"; ?>





// -->
</script>
<center>

<form name="form1"action="http://192.168.1.126/intranet/bandwidth ... esults.php" method="POST">
<input type = "hidden" name = "customer" value = "<?php echo $customer = $_POST['customer']; ?>"><?php echo $customer; ?>
<input type = "hidden" name = "kbps" value = "<?php echo $kbps; ?>"><?php echo $kbps; ?>
<input type = "hidden" name = "downloadtime" value = "<?php echo $downloadtime; ?>"><?php echo $downloadtime; ?>
<input type = "hidden" name = "KB" value = kbytes_of_data><?php echo $KB; ?>
<input type = "hidden" name = "recorded" value = "<?php echo $recorded; ?>"><?php echo $recorded; ?>

</form>

</body>
</html>
Post Reply