I am trying to do a for loop that increases the value of $i everytime it goes through the loop and attaches that value to the end of string to create a new variable name AND to match the title of a column in the database.
I have created variables that are labelled as follows:
$textfield1, $textfield2, $textfield3 ... $textfield20
in the database, I have columns named:
a1,a2,a3 ... a20
I want the data in $textfield1 to write to a1, $textfield2 to write to a2, etc.
I was hoping to be able to do it by creating the loop below and having $textfield[$i] and a[$i].
I have done it like this because the user specifies the number of variables created (this is stored in $number) on a previous page.
The part of the loop that isn't working is in the $query where
a[$i] and $textfield[$i] do not seem to want to write anything to the database.
for ($i = 1; $i <= $number; $i++)
{
$textfield[$i] = $HTTP_POST_VARS[$i];
//statement to insert all data into the database
$query = "INSERT INTO tblamenities (name,a[$i])
VALUES ('$name','$textfield[$i])";
//execute insert statement
$result = mysql_query($query);
}