[SOLVED] Array headache
Posted: Fri Mar 24, 2006 1:01 am
Hi guys I am having a problem passing an array with post here is my first page code
this is just a basic page I created to see that it was passing properly and it wasn't here is the page it transfers to
Basically the variables dont seem to be getting picked up by the second page when I tested just passing one name and 1 last name no problem simple variables if your wondering what the second page does is it creates a user name from the first and last name not exceeding 20 chars(windows limit on logins).
I thought I was finally getting a grasp on arrays but I am starting to think I am missing something simple or I have made a stupid mistake somewhere.
Code: Select all
<form action="add_student_db.php" method="post" ENCTYPE="multipart/form-data">
<table cellpadding="2" cellspacing="2" border="1" width="100%">
<?
for ($n=1;$n<13;$n++)
{
?>
<tr>
<td><b>First Name</b>:</td>
<td><input type="text" name="first_name[<? echo $n ?>]" size="45"></td>
</tr>
<td valign="top"><b>Last Name </b>:</td>
<td><input type="text" name="last_name[<? echo $n ?>]" size="45"></td>
</tr>
<tr>
<td><b>Password(min 4 Digits </b>:</td>
<td><input type="text" name="pass_4[<? echo $n ?>]" size="45"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<?
}
?>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Enter"></td>
</tr>
</table>
</form>Code: Select all
<?php
$count = 0;
for ($n=1;$n<13;$n++)
{
$count = $count+1;
$first_name[$n] = $_POST['first_name[$n]'];
if ($first_name[$n] != "")
{
echo $first_name[$n];
$last_name[$n] = $_POST['last_name[$n]'];
$sin_4[$n] = $_POST['sin_4_$n'];
$username[$n] = $last_name[$n].$first_name[$n].date("my");
$userlength[$n] = strlen($username[$n]);
if ($userlength[$n] > 20)
{
$adjust[$n] = $userlength[$n] - 20;
$new_length[$n] = strlen($first_name[$n]) - $adjust[$n];
$new_first[$n] = substr($first_name[$n], 0, $new_length[$n]);
$final_username[$n] = $last_name[$n].$new_first[$n].date("my");
$final_username[$n] = strtolower($final_username[$n]);
}
else
{
$final_username[$n] = strtolower($username[$n]);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Student Username</title>
</head>
<h3>Here is the studend ID</h3>
<?php
for ($m=1;$m<$count;$m++)
{
print "Your username is $final_username[$m]"; ?><br /><?php
}
?>
<body>
</body>
</html>I thought I was finally getting a grasp on arrays but I am starting to think I am missing something simple or I have made a stupid mistake somewhere.