Handling HTML Form Array with PHP
I'm having a really hard time trying to figure out how to handle this:
I'm trying to create two arrays, where I enter 4 quizzes for a class, and then loop through them in my PHP code.
<tr>
<td>ENGL110</td>
<td><input type="text" name="EnglArray[]"></td>
<td><input type="text" name="EnglArray[]"></td>
<td><input type="text" name="EnglArray[]"></td>
<td><input type="text" name="EnglArray[]"></td>
</tr>
<tr>
<td>MATH242</td>
<td><input type="text" name="MathArray[]"></td>
<td><input type="text" name="MathArray[]"></td>
<td><input type="text" name="MathArray[]"></td>
<td><input type="text" name="MathArray[]"></td>
</tr>
This is how I'm trying to retrieve it in my PHP code
$EnglArray = $_POST["EnglArray"];
$MathArray = $_POST["MathArray"];
print_r($EnglArray);
I can't figure out what I'm doing wrong, but it seems like my array is always empty, andprint_r
doesn't output anything.
Answer
Solution:
This should work.