I just started with php and I'm trying to make a simple interface as
follows:
- user is asked to input an integers, for example: how many students do
you want to enter?
- user is then shown a page with number of text boxes = number he gave
at the previous page
- user fills out the test boxes with names of students and clicks
submit
- the user is sent to another page where the above names are output to
the screen
here is the code for the relevant pages:
First i ask for how many text boxes the user would like...
================================================== ====================
<?
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>ECSLAB Submit System Course Registration</title>
</head>
<body>
<table>
<tr>
<td>
<p>
<?
if($_SESSION['sizeerror']) {
echo "Inputs must be
integers<br><br>";
$_SESSION['sizeerror'] =
0;
}
?>
<form method="POST"
action="transition.php">
How many instructors (TAs,
professors, etc) will need access to the system?<br>
<input type="text"
name="numinstructors" size="20"><br><br>
How many students would you like
to add?<br>
<input type="text"
name="numstudents" size="20"><br><br><br>
<input type="submit"
value="Submit" name="B1">
</form>
</p>
</td>
</tr>
</table>
</body>
</html>
================================================== ========================
if the input was correct (both were integers) you get redirected to the
next page...this part works fine (or so it seems). it displays the
correct number of text-boxes...
================================================== ========================
<?
session_start();
?>
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>ECSLAB Submit System Course Registration</title>
</head>
<body>
<table align="center">
<form method="POST" action="submit.php">
<tr>
<p>
Coursename: <input type="text"
name="coursename" size="20"><br><br>
</p>
</tr>
<tr>
<p>
Instructor ECS Lab Accountnames:<br><br>
<?
for( $k = 0; $k <
$_SESSION['numinstructors']; $k++){
echo "<input type=\"text\"
name=\"instructor[$k]\" size=\"20\"><br><br>";
}
?>
</p>
</tr>
<tr>
<p>
<br><br>Student ECS Lab Accountnames:<br><br>
<?
for( $i = 0; $i <
$_SESSION['numstudents']; $i++ ){
echo "<input type=\"text\"
name=\"student[$i]\" size=\"20\"><br><br>";
}
?>
<input type="submit" value="Submit" name="B1">
</p>
</tr>
</form>
</table>
</body>
</html>
================================================== =======================
submitting the names sends you to the following page...
================================================== ========================
<?
session_start();
$coursename = $_POST['coursename'];
$_SESSION['coursename'] = $coursename;
for( $i = 0; $i < $_SESSION['numstudents']; $i++ ){
$idx = 'student[' . $i . ']';
$student[$i] = $_POST[$idx];
$_SESSION[$idx] = $student[$i];
}
for( $k = 0; $k < $_SESSION['numinstructors']; $k++ ){
$instructor[$k] = $_POST["instructor[$k]"];
$_SESSION["instructor[$k]"] = $instructor[$k];
}
?>
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>ECSLAB Submit System Course Registration Successful</title>
</head>
<body>
<?
for( $i = 0; $i < $_SESSION['numstudents']; $i++ ){
$x = 'student[' . $i . ']';
echo $_SESSION[$x];
echo "<br>";
}
echo "now instructors<br>";
for( $k = 0; $k < $_SESSION['numinstructors']; $k++ ){
$x = 'instructor[' . $k . ']';
echo $_SESSION[$x];
echo "<br>";
}
?>
</body>
</HTML>
================================================== ======================
i expect it to print something like:
student1
student2
student3
now instructors
teacher1
teacher2
but instead it prints:
now instructors
(so, 3 blank lines, "now instructors", then 2 blank lines)
Anyone have any idea what I'm doing wrong?
Thanks in advance,
--Lucas