Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:05:49+00:00 2026-05-13T14:05:49+00:00

I am admittedly not as skilled in PHP as I would hope to be.

  • 0

I am admittedly not as skilled in PHP as I would hope to be. Most of my experience is with WordPress loops.

I’m trying to create a very simple quiz that carries the number of correct answers in the URL (eg. domaindotcom/?p=3 if they’ve got 3 correct answers so far).

I’m using the following PHP code to start it off:

<?php 
    /* Gets current correct answer Count */ 
    $answer_count = $_GET["p"]; 

    /* checks to see if the submitted answer is the same as the correct answer */
    if ($_POST["submitted-answer"] == "correct-answer") {
        $answer_count++;
    }
?>

Now I know I can get the correct link by using the link:

<a href="link-to-next-question.php/?p=<?php echo $answer_count; ?>">Next Question</a>

But now I’m trying to use it in a form and confused by POST, GET, etc.

Here’s my HTML:

<form name="quiz" action="" method="POST">
<label for="o1"><input type="radio" name="grp" id="o1" value="o1"> Label 1</label>
<label for="o2"><input type="radio" name="grp" id="o2" value="o2"> Label 2</label>
<label for="o3"><input type="radio" name="grp" id="o3" value="o3"> Label 3</label>
<input type="submit" value="Next Question" class="btn">
</form>

How can I choose the correct answer (security not important, it’s just a fun quiz) and then send them along to the next URL while adding the increment to the $answer_count before the URL is created?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:05:49+00:00Added an answer on May 13, 2026 at 2:05 pm

    Don’t pass the answer count in the link (i.e. by GET). Instead just include a hidden form field(s), and use client side javascript code to increment variables you want and submit the form.

    <form id="qfrm" name="quiz" action="" method="POST"> 
      <input type="hidden" name="question_number" value="<?php echo $next_question_number?>">
      <input type="hidden" id="n_c_a" name="num_correct_answers" value=<?php echo $num_correct_answers?>">
      <input type="button" value="Submit" onclick="validateAnswerAndSubmit(); return false;">
    </form>
    
    <script language="javascript">
      function validateAnswerAndSubmit(){
        if(validate_answer()){
          document.getElementById("n_c_a").value += 1;
        }
        document.getElementById("qfrm").submit();
      }  
    </script>
    

    Then just make your php script switch on $_POST["question_number"]


    OK so you don’t want to use javascript… if you’re really asking “how do I know which radio box was selected from PHP?” the answer is:

    <?php $answer = $_POST["grp"]; ?>
    

    I think you should really be passing two variables in the URL, one would be the question_number, and the other would be num_correct. You could then write code like this:

    <?php
    
    $num_correct = (int) $_GET["num_correct"];
    $question_number = (int) $_GET["question_number"];
    
    switch($question_number - 1){ // assuming your question numbers are in order by convention
                                  // validate the answer to the previous question
      case -1: //no validation necessary for the first question ($question_number 0)    
        break;
      case 0: 
        if($_POST["grp"] == "correct answer"){
          $num_correct++;
        }
        break;
    
       // and so forth;         
    }       
    ?>
    
    <form name="quiz" 
          action="this_page.php/?num_correct=<?php echo $num_correct;?>&question_number=<?php echo $question_number + 1?>" 
          method="POST">
    
    <?php Display_Question_Number($question_number);?>
    
    </form>
    

    The key point here is that “action=” in the form is analogous to “href=” in the anchor, i.e. it’s the URL to which the form is submitted when the user clicks the submit button.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm about finished with my latest project, a (admittedly not very good)
Compared to most people on this site I am admittedly a novice. I wanted
(The title is admittedly not that great. Please forgive my English, this is the
I am trying to create a custom control based on the TCustomComboBox in Delphi
I'm looking at options for providing Faceted Search functionality, admittedly not a specialty of
Given a table: CREATE TABLE [GENERIC_TABLE] ( [RECORD_ID] [int] IDENTITY(1,1) NOT NULL, [SHORT_DESC] [varchar]
Admittedly, creating extmap.xml files is relatively simple: http://msdn.microsoft.com/en-us/library/dd833069(VS.95).aspx But while many third-party libraries provide
Admittedly not a programming question, but I don't really know where else to ask
This is admittedly similar to (but not a duplicate of) Comparison of full text
This is very odd I'm reading some (admittedly very large: ~2GB each) binary files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.