I have a bunch of questions for users listed in an xml file (along with other stuff). i use simplexml_load_file to load the xml then php displays the first question in the xml file and generates a form with which users can give their answer to that question. when the form is submitted, those answers are saved somewhere else, a counter advances one click and the same page is then displayed again with the intention that the next question in the xml file (referenced by the counter) will be displayed.

Thing is, it all works fine the first time but second time round, nothing from the xml file gets displayed. But I dont get an error saying that the xml file has not loaded. What is happening?

Here is simplified code (in test.php):

//load XML
if(!$xml=simplexml_load_file('test.xml')){
trigger_error('Error reading XML file',E_USER_ERROR);
}


//get number of last question
if (isset($_POST[newQuestionNumber]))
{
$questionNumber= $_POST[newQuestionNumber];
}
else
{
$questionNumber = 0;
}


$question = $xml->question[$questionNumber];

//its the second bit of this that displays nothing second time around but should display text of second question
echo "The question number is $questionNumber. The question is $question->text";
echo "<form action = 'test.php' method ='post'>";
$questionNumber++;
echo "<input name='newQuestionNumber' type ='hidden' value=$questionNumber>";
echo "<input type='submit' value = 'Submit'>";

The test.xml looks like this:

<questions>
<question>
<text>a question?</text>
</question>

<question>
<text>another question?</text>
</question>

<question>
<text>yet another question?</text>
</question>

</questions>

I am new to all this so please be gentle with me!