Looping Form Generation - Refering to Controls
I think this is above the beginner level, so, I put it here.
I have the following form generated (very simple version):
<?php
$numpoints = 3;
$endcount = $numpoints + 1;
echo "<form action='http://www.geft-online.org/test4.php' method='POST'>
<table align='center' border='1' cellspacing='2' cellpadding='2'>
<tr><th align='center' colspan='3'>Enter Point Information Below
<input type='text' name='numpoints' value='$numpoints'</th></tr><form>";
for($counter=1; $counter<$endcount; $counter++)
{
echo "<tr><td><input type='text' name='test$counter'><td><tr>";
}
echo "<tr><td colspan='3' align='center'><input type='submit' value='Submit'></td></tr>";
echo "</form></table>";
?>
Which, refers to this page to run the data:
<?php
require('config.php');
$point_id = 0;
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB,$conn);
$numpoints = $_POST['numpoints'];
$endcount = $numpoints + 1;
for($counter=1; $counter<$endcount; $counter++)
{
echo $_POST['test$counter'];
$sql = "INSERT IGNORE INTO tbltest VALUES (NULL, ' " . $_POST[' " . "test" . $counter . "'] . " ')";
mysql_query($sql) or die("Its ****ED!" . mysql_error());
}
echo $numpoints;
echo "CHECK DATABASE!";
?>
Its the values part of the SQL I cant seem to get to work.
My form is generated, and the control is named test$counter...it works out to be test1, test2, test3, and so on....
Now, I guess I need to know if I can use a variable in the $_POST statement, such as $_POST['test$counter'], to retrieve the data for test1, test2, and all the other ones.
If anyone knows that you can do this for sure, or maybe has a different way of collecting the data, I'd greatly appreciate the help. I'm basically a hobbyist, doing this to help out a college team I volunteer coach, and looking to create a website the team can use to track stats and results. Thanks for the info in advance!
|