Page 1 of 1

interaction between two pages...

Posted: Fri Nov 14, 2003 1:44 am
by netooi
Ok, I have 2 webpages that i have a popquiz type website on..
On page 1 i will post a question, then the user selects and answer
and hits the submit button, and it goes to page 2 to see if the answer was correct.

Then after user clicks next button on page2 we go back to page 1 and
it displays the 2nd question and so on....

My problem is i need a good way to keep the user from using the back button to go to previous questions. It causes problems because i keep track in a database of what question they are on.

My unsuccessful attempt at a solution i've thought of so far is the following:

Page1: In the onclick event for the button to check the answer I set a session variable so that I could check on the next page if the variable was set, then set it to NULL on page 2.

Page2: Same thing, for the next button to go to next question, i set a different session variable in the onclick event so i could check on the next page if the variable was set, then set it to null on page1.

See where i'm going? If I hit the back button from page 2 to page 1, then I was thinking the session variable would not have been set since it was in the onclick action for the button.

However, this approach is not working...

Is there any good suggestions for how to handle this? I'm pretty new at php and web page stuff.. Using session variables might be off the wall for this, its just what came to my head.
Thanks,

Posted: Fri Nov 14, 2003 1:53 am
by Paddy
Instead of going back and forward between pages why don't you just do it in one page? Then if they press back the page would be expired. I wouldn't use session variables for this one.

Posted: Fri Nov 14, 2003 1:55 am
by netooi
The page would be expired...
Do you have to have no-cache option on for that?

Posted: Fri Nov 14, 2003 2:06 am
by Paddy
Hmmm...not sure. Sorry.

Posted: Fri Nov 14, 2003 2:41 am
by infolock
netooi, why would the page be expired if you just did all the questions on one page? however, even if let's say for argument sakes that you we go ahead and work with it the way it is. There should be no problem with the user having already made a decision on the page, and then going back to change their answer.

All you would have to do is a simple query command, asking "Select answer from bob". then you could query that, and if you find a result, tell it to drop the answer, and update accordingly. In other words, you could do it like this :

Code: Select all

<?php

$SQL = "Select question_1_answer from bob";
$RESULT = MySQL_Query($SQL);
$rows = MySQL_num_rows($RESULT);

if ($rows > 0)
{
    $sql2 = "delete from bob where question_1_answer = '.$_POST.'";
    $result = MySQL_Query($sql2);
}
?>
that code may not be exactly right ( as it is untested ), but you get the point. You could put the first query at the beginning the of page, and then the " if ($rows >o) " statement within the POST Button.

Hope that helps.

Posted: Fri Nov 14, 2003 6:29 pm
by netooi
I've got it taken care of now thanks for the suggestions guys.