Help In Generating An Online Quiz

Discussion in 'PHP' started by cmillett0, May 13, 2007.

  1. #1
    I need assistance in generating an online quiz via PHP, HTML, and possibly JavaScript. I want to generate 10 sets of math problems with random numbers. I have successfully used the rand() function with lower and upper limits to generate the question values. For each problem, I want the user to see a refreshed screen with the problem and then enter the answer for that problem. I have successfully set up an HTML <form> to accepted the answer. After all 10 problems have been asked and answered, I want to display all 10 problems with the user's corresponding answers (to summarize what was asked and the matching reply).

    I am having difficulty saving the 10 sets of values for the geneated numbers and the user's 10 inputted answers. I initially set up the PHP module to issue a <form> with method="post". When I viewed the values of the variables, I only saw the value entered in the current form. The previously generated values and input answers were lost (and came up a null or blank).

    So how can I retain all values as I go back and forth between question and answer (with a screen refresh each time)?
     
    cmillett0, May 13, 2007 IP
  2. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not use PHP built-in session mechanism? Session is a way to store user data on the server. It is exactly what you need. All the handling is automatic -- all you have to do is just store your data.

    Google for "PHP sessions". You should find something useful.
     
    xooMan, May 13, 2007 IP
  3. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Store it in session as xooMan said it is better option and then display the quiz.
     
    Subikar, May 13, 2007 IP
  4. cmillett0

    cmillett0 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am fairly new to PHP programming and was not familiar with the Session feature. It incorporated it into my quiz processing, and it worked exactly as I needed it to do!!! Thank you so much for the recommendation. :)
     
    cmillett0, May 14, 2007 IP
  5. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #5
    use serialize in session :)
     
    gibex, May 14, 2007 IP
  6. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #6
    you can use hidden forms(<input type=hidden >) to store the questions and answers and pass them from the question page to the result page and then pass them from result page to answer showing page.
     
    coderbari, May 14, 2007 IP
  7. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Glad to help you ;)
     
    xooMan, May 14, 2007 IP