PHP Form help


I have an assignment that i failed to complete correctly for school. It has already been graded but I need to figure out how to do it for future reference. She wants us to create a html form that will allow users to continuously add animals to an array. She wants the array to be displayed every time the user adds a new animal.

No matter how many different ways I have tried this, I am only able to save the last animal entered. The array never gets any larger than 1 element. She said we need to take the post data and push it onto an array and then loop through the array to display all the elements.

first thing:
Can someone verify the correct way to accept multiple entries with the same input line?

second thing:
Im not at home right now but my code looks something like this. I’ve tried everything I can think of but I can only get the last element to display.

<?php $animalArray = $_POST["animal"]; $arrLength = count($animalArray); for(index=0;index<arrLength;index++) { echo "$animalArray[index]"; echo "
"; } ?>


When your assignment was graded, suggestions should have been given on what would have been some of the acceptable methods to use. Programming is not a subject that you can just assign a grade to the result and go onto the next lesson. Either the instructor doesn’t know the subject or gave prior instructions on a specific method that was expected to be used.

As to answering your thread. Web servers are stateless. Remembering prior selections will require propagating them between requests. One way of doing this would be to pass them through the form. I suspect you ware supposed to dynamically produce the form, populating the form field values with the existing selections, and provide a new empty form field for the next selection. This would both display the existing values and allow entering another one. You could also specifically just display the existing values, pass them through the form using hidden fields, and provide a new empty form field for the next selection.