Hi! I am a total newbie but I thought I could make this quiz script work.

Here is the first page:

http://www.radiofreejericho.com/thanksgiving.html

I had found the script on the web and thought I might be able to tweak it to be able to get it to do what I want it to do (hey, it worked for CSS, lol)

Here is the link to where I got the script:
http://www.datingdiversions.com/tutorial/page3.html

What I would like is for it to score the answers - multiple questions, multiple answers. (so if you score more Jake answers, you get Jake, etc..)
But I am finding that I have no idea how to make it do that... sigh. I have tried looking at other scripts to no avail.

Would anyone be willing to help me?
Thank you so much,
Vicki :-)

    Okay... and the code you're using is?

      bpat1434 wrote:

      Okay... and the code you're using is?

      PHP

        Sorry, you misunderstood me: What code (not language) are you using? What files have you got and what is the code you're using? not just the tutorial you followed because I'm sure that when I follow the tutorial, I'll get it to work. So post your code.

          This is my quiz page:

          <form action="results.php" method="post">
          <b>Question 1: What are you thankful for this year?</b><br>
          <input type="radio" name="q1" value="Jake">
          being home<br>
          <input type="radio" name="q2" value="Stanley">
          having found love<br>
          <input type="radio" name="q3" value="Jonah">
          having a successful year<br>
          <input type="radio" name="q4" value="Eric">
          I can't decide<br>
          <input type="radio" name="q5" value="Jimmy">
          having good friends<br>
          <input type="radio" name="q6" value="Bill">
          being with family and friends<br>
          <input type="radio" name="q7" value="Hawkins">
          being with my family<br>
          <br>
          <b>Question 2: What type Thanksgiving Dinner do you like best?</b><br>

                    <input type="radio" name="q1" value="Jake">
                    lots of turkey<br>
                    <input type="radio" name="q2" value="Stanley">
                    traditional family recipies<br>
                    <input type="radio" name="q3" value="Jonah">
                    easy to please, anything is good<br>
                    <input type="radio" name="q4" value="Eric">
                    ham<br>
                    <input type="radio" name="q5" value="Jimmy">
                    one I don't have to cook<br>
                    <input type="radio" name="q6" value="Bill">
                    anything as long as there is stuffing<br>
                    <input type="radio" name="q7" value="Hawkins">
                    formal with a variety of old and new dishes<br>
                    <br>
                    <b>Question 3: Things get a little silly in the kitchen, and you...?</b><br><input type="radio" name="q1" value="Jake">
                    grab the can of whipped cream<br>
                    <input type="radio" name="q2" value="Stanley">
                    get a spoon full of mashed potatoes<br>
                    <input type="radio" name="q3" value="Jonah">
                    arm yourself with the turkey baster<br>
                    <input type="radio" name="q4" value="Eric">
                    tell everyone to behave<br>
                    <input type="radio" name="q5" value="Jimmy">
                    reach for the salad tongs<br>
                    <input type="radio" name="q6" value="Bill">
                    sit back and watch the action<br>
                    <input type="radio" name="q7" value="Hawkins">
                    grab a turkey leg and run<br>
                    <br>
          
                    <b>Question 4: What kind of pie is your favorite for Thanksgiving?</b><br>
                    <input type="radio" name="q1" value="Jake">
                    cherry<br>
                    <input type="radio" name="q2" value="Stanley">
                    peach<br>
                    <input type="radio" name="q3" value="Jonah">
                    mince meat<br>
                    <input type="radio" name="q4" value="Eric">
                    apple<br>
                    <input type="radio" name="q5" value="Jimmy">
                    coconut cream<br>
                    <input type="radio" name="q6" value="Bill">
                    pecan<br>
                    <input type="radio" name="q7" value="Hawkins">
                    cheese cake<br>
                    <br>
          
                    <b>Question 5: What do you do after dinner?</b><br>
                    <input type="radio" name="q1" value="Jake">
                    head out to visit friends<br>
                    <input type="radio" name="q2" value="Stanley">
                    go for a long walk<br>
                    <input type="radio" name="q3" value="Jonah">
                    chill out with a beer<br>
                    <input type="radio" name="q4" value="Eric">
                    play football<br>
                    <input type="radio" name="q5" value="Jimmy">
                    talk about what you want for Christmas<br>
                    <input type="radio" name="q6" value="Bill">
                    watch the game<br>
                    <input type="radio" name="q7" value="Hawkins">
                    get a little work done<br>
                    <br>
          
                    <input type="submit" value="Determine Your Thanksgiving date" name="submit">
                  </form>[/QUOTE]

          This is at the top of the result page, before the html starts:

          <?php
          $score = 0;
          if ($POST['q1'] == 'Jake')
          $score++;
          if ($
          POST['q2'] == 'Stanley')
          $score++;
          if ($POST['q3'] == 'Jonah')
          $score++;
          if ($
          POST['q4'] == 'Eric')
          $score++;
          if ($POST['q5'] == 'Jimmy')
          $score++;
          if ($
          POST['q6'] == 'Bill')
          $score++;
          if ($_POST['q6'] == 'Hawkins')
          $score++;
          ?>

          and this is where it is supposed to show the results in the body of the page:

          <?php
          echo '<b>Your Perfect Date is ' . $score . '/5</b><br><br>';
          if ($score < 3)
          echo 'You are not very cool!';
          else if ($score == 0)
          echo 'Congratulations, a perfect score!';
          else
          echo 'Not bad, you scored average';
          ?>

          I think it is in this last part that it isn't working for a multiple choice - multiple answer. (but I could be totally wrong, lol)

          Thanks :-)

            Hmm... let's step through this:

            Each input has a name: q1, q2, q3 ... q6
            Each input has a value: Jake, Stanley, Jonah ... Hawkins

            Now, in your PHP you ask if q1 == Jake.... if they select Jake in any of the radio-buttons, that will result in a true answer, not necessarily a true answer for question 1.

            Radio buttons work together so that you have one name for a group of radio buttons (like "q1" being the name of the group of available answers for question 1). For example:

            <b>Question 1: What are you thankful for this year?</b><br>
            <input type="radio" name="q1" value="Jake">being home<br>
            <input type="radio" name="q1" value="Stanley">having found love<br>
            <input type="radio" name="q1" value="Jonah">having a successful year<br>
            <input type="radio" name="q1" value="Eric">I can't decide<br>
            <input type="radio" name="q1" value="Jimmy">having good friends<br>
            <input type="radio" name="q1" value="Bill">being with family and friends<br>
            <input type="radio" name="q1" value="Hawkins">being with my family<br>

            Then, the next group (question 2) would all have a name of "q2" instead of q1. Then you could do your scoring properly.

            Now, radio-buttons don't allow multiple items to be selected (hence their reason for being there 🙂 ) but check-boxes do. Checkboxes can be made "arrays" of values. So by appending an opening and closing square-brace to the name, we make it a checkbox that will send multiple values through to our PHP script. For example:

            <b>Question 1: What are you thankful for this year?</b><br>
            <input type="checkbox" name="q1[]" value="Jake">being home<br>
            <input type="checkbox" name="q1[]" value="Stanley">having found love<br>
            <input type="checkbox" name="q1[]" value="Jonah">having a successful year<br>
            <input type="checkbox" name="q1[]" value="Eric">I can't decide<br>
            <input type="checkbox" name="q1[]" value="Jimmy">having good friends<br>
            <input type="checkbox" name="q1[]" value="Bill">being with family and friends<br>
            <input type="checkbox" name="q1[]" value="Hawkins">being with my family<br>

            Now, in our PHP script we can check to see the answer of question 1. For radio buttons, what you have originally will work since only one answer can be correct. For checkboxes, we have to use [man]in_array[/man] or [man]array_search[/man] to see if what they submitted is an answer worth points:

            if(in_array('Jake', $_POST['q1']))
               $score++;

            And so on for however many questions you decide to have.

            Hope that helps.

              Thank you so much!!! I can understand that!!!

              Vicki :-)

                Write a Reply...