I'm really stuck on this. I have tried to solve this issue several ways. When the user gets redirected to this page I have the page grab from a mysql table an x amount of entries based off the amount of rows in the table for that user and print them to the screen like this.
The schema:
Title Max Score
Test1 100 ?
Please Submit values below:
Row 1 Title: [ text field area] [submit button]
Row 2 Title: [text field area] [submit button]
... and so forth
The user is suppose to enter the values(score) for those table entries. My problem is I cannot dynamically name the text field such that the fields have different names.
For instance here is a code snippet I found for checkboxes and is similar to what I need.
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Select the programming languages you can use<br>
<input name="language[]" type="checkbox" value="C++">
C++<br>
<input name="language[]" type="checkbox" value="Java">
Java<br>
<input name="language[]" type="checkbox" value="PHP">
PHP<br>
<input name="language[]" type="checkbox" value="ASP">
ASP<br>
<input name="language[]" type="checkbox" value="Delphi">
Delphi<br>
<input name="send" type="submit" id="send" value="Send!">
</form>
<?php
if(isset($_POST['language']))
{
$language = $_POST['language'];
$n = count($language);
$i = 0;
echo "The languages you selected are \r\n" .
"<ol>";
while ($i < $n)
{
echo "<li>{$language[$i]}</li> \r\n";
$i++;
}
echo "</ol>";
}
?>
what i have is this and it only works for the first field. no matter which of the submit buttons is pressed only the first text fields data is printed.
$grabfields=mysql_query("select FieldName from $calc");
$i=0;
while($fieldnames=mysql_fetch_row($grabfields))
{
$_SESSION["main[$i]"]=$fieldnames[0];
if(strcmp($i,0)==0)
{
echo "<div align='center'>";
echo "<table border='border'>";
echo "<form action='Calculate.php' method='Post'>";
echo "<caption><h3>Calculate Grades</h3></caption>";
echo "<th>Weights</th>";
}
echo "<tr align='right'><td>";
echo $fieldnames[0]; //prints the assignment name in front of text field
echo " : <input type='text' name='paste[]' size='20' maxlength='20'> <input type='submit' value='Add Weight' ></td></tr> ";
$i++;
}
echo "</form>";
echo "</table>";
echo "</div>";
if(isset($_POST["paste"]))
{
$paste=$_POST["paste"];
$n=count("$paste");
$k=0;
while($k<$n) //print values for testing purposes
{
echo $paste[$k];
$k++;
}
}