Ok, I got the form to do just what I want. It shows up correctly, but data isn't inserting right into the mysql database. Any advice?
Here is the code for the form. It creates a top row of headers, a side row of headers and then data fields all in between based off of someone saying they want X number of columns and X number of headers.
echo "<table><td></td>";
for($h = 0; $h < $_POST['columns']; $h++) {
echo "<td><input name='header_top" . $h . "' size='10'></td>";
}
for($i = 0; $i < $_POST['rows']; $i++)
{
echo "<tr><td><input name='header_side" . $i . "' size='15'></td>";
for($j = 0; $j < $_POST['columns']; $j++) {
echo "<td><center><input name='data" . $j . "' size='5'></center></td>";
}
}
echo "<br></tr></table>";
I have it submiting to another file that tries to process the data. The part I am having trouble with is the second file. The code that is handling the data from above is here:
include("array1.php");
$tcArray = orderArray($_POST); //reorder the list so that they are numeric
for($h = 1; $h < count($tcArray); $h = $h + 1)
{
$header_top1 = $tcArray[$h + 1]; //top header
}
for($j = 1; $j < count($tcArray); $j = $j + 1)
{
$data1 = $tcArray[$j + 1]; //data
}
for($i = 1; $i < count($tcArray); $i = $i + 1)
{
$header_side1 = $tcArray[$i + 1]; //side header
}
From there I just have a mysql insert handling the variables. The array1.php file is below:
function orderArray($array)
{
foreach ($array as $key)
{
$newArray[$i] = $key;
$i++;
}
return $newArray;
foreach ($array as $key)
{
$newArray[$j] = $key;
$j++;
}
return $newArray;
foreach ($array as $key)
{
$newArray[$h] = $key;
$h++;
}
return $newArray;
}
One last item to note, right now I was just trying to get 1 data field, 1 header top and 1 header side to work and then I could enter variables for another max number of fields from there.. but one doesnt even seem to work right. some data enters but it is usually the wrong field and never all of them.
I am sure this is all a bit of a mess and tons done wrong, but any adivce would be apprecaited. thanks again!