Forum Moderators: coopster

Message Too Old, No Replies

POST elements not registering in session array

session array elements

         

kiaoi

12:09 am on Jun 17, 2007 (gmt 0)

10+ Year Member



Hi,
I've been stumped by this for hours! I have a quiz that uses displays one question at a time. So I have a form embedded in php (is this allowed) since I want to control how many questions to randomly choose. Anyway I have a POST action that submits to the same file as I want to use the same radio buttons.

echo "<form id=\"form2\" name=\"form2\" method=\"post\" action=\"lin_solv_qz.php\">
<p>
<label>......
......
....
</form>"

Can you call itself back to the same file by using the same file name or should you do it like this:

action=\"print $_SERVER['PHP_SELF']\">

well thats not the main problem. After I POST I want to be able to retrieve the answer and store it in an array which I try by:

//check everything works
$array_number = $_SESSION['qnumber'];
$thisanswer = $_REQUEST['radio2'];
echo "the array number is $array_number and the answer is $thisanswer <p></p>";

//store and display array
array_push($user_ans1, $thisanswer);
foreach ($user_ans1 as $abcde) {
print "$abcde <br/>";
}

The first half displays but the second half doesn't. Any ideas?
Thanks

Habtom

5:02 am on Jun 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> array_push($user_ans1, $thisanswer);

I am not sure what you are trying to achieve at this stage. I can't see what $user_ans1 is, and the function seems to be used wrongly, i give you an example of array_push:

$a=array("Apple","Orange");
array_push($a,"Akat","Beles");
print_r($a);

:) go figure what Akat and Beles are.

>> action=\"print $_SERVER['PHP_SELF']\">

This part needs to be done differently. you need to take out the print as the line is already embeded in PHP.

Habtom