I'm converting an existing survey from Perl to PHP. The way I've done it in Perl is that an HTML form calls a Perl script when the submit is clicked. The script will read the fields, generate a timestamp, write the data to a database and then generate the next page by calling a subroutine that holds the code for the next page. I use hidden fields to move the timestamp from page to page. I use it to identify the respondent as data is written to various tables.
I try to do the same with PHP but the hidden variables show up blank in the new page.

Here's the code for the script to process the first page and generate the second page:

<?php
include("oldmisc.inc");
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$IP=$REMOTE_ADDR;

Generate and format the timestamp.

$datein=date("YmdHis");
$query = "INSERT INTO habits (datein,readcurrent)
values ('$datein','$readcurrent')";
$result = mysql_query($query);
$datein= $datein;
header("Location: ../pages/hiddentest.php");
?>

Here's the page called by the header statement:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Pizza This! Survey -- Question # 2</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form method="post" action="survey_3.php">
<p>2. What's your favorite cheese, <?php echo $datein; ?>?</p>
<fieldset>

<select name="cheese">
<option selected="true" value="">[choose one]</option>
<option value="Mozzarella">Mozzarella</option>
<option value="Provalone">Provalone</option>
</select>
</fieldset>
<br />
<fieldset>
<input type="submit" value="Go to #3" />
<input type="reset" value="Reset Form" />
</fieldset>
<input type="hidden" name="datein" value="<?php echo $datein; ?>" />
</form>
</body>

I thought that the timestamp generated by the script would appear in this page, but it doesn't. What am I doing wrong?

    Write a Reply...