Page 1 of 1

Passing Variables from an html form through three php pages

Posted: Tue Sep 02, 2003 3:59 pm
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

Posted: Tue Sep 02, 2003 4:03 pm
by JayBird
why do you need to pass through 3 php pages?

how are you redirecting to each page?

Posted: Tue Sep 02, 2003 4:36 pm
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.

Posted: Tue Sep 02, 2003 5:18 pm
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

Posted: Tue Sep 02, 2003 11:10 pm
by dschuckman
How do I pass them with posts and gets beyond the first page?

Posted: Wed Sep 03, 2003 2:56 am
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

Posted: Wed Sep 03, 2003 5:28 am
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

Posted: Wed Sep 03, 2003 10:40 am
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?

Posted: Wed Sep 03, 2003 12:57 pm
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;

Posted: Wed Sep 03, 2003 2:18 pm
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>