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 7890731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:25:56+00:00 2026-06-03T06:25:56+00:00

I have a php page with multiple choice quiz questions like this <p>1. Is

  • 0

I have a php page with multiple choice quiz questions like this

<p>1. Is Manhattan near New York?<br>
    <input type="radio" name="ans1" value="3">
    Yes<br>
    <input type="radio" name="ans1" value="2">
    Maybe<br>
    <input type="radio" name="ans1" value="1">
    No</p>
  <p>2. Do you like Indian food?<br>
    <input type="radio" name="ans2" value="1">
    Some times<br>
    <input type="radio" name="ans2" value="3">
    Never<br>
    <input type="radio" name="ans2" value="2">
    Always</p>

The page posts to itself and checks if the answer is right or wrong like this

if($ans1 == "3") { 
$test_complete .="Question one is <span class='green'>correct</span>, well done!<br/>";  
}else{ 
$test_complete .="Question one is <span class='red'>incorrect</span>!<br/>"; 
} 
// change the quest2 to the right answer
if($ans2 == "2") { 
$test_complete .="Question two is <span class='green'>correct</span>, well done!<br/>"; 
}else{ 
$test_complete .="Question two is <span class='red'>incorrect</span>!<br/>"; 
}

Now instead of telling the user that answer one or two is correct i would like to run a counter where it calculates the number of correct and number of wrong answers and displays it in two table boxes along with one box for total number of questions.

  • 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-06-03T06:25:57+00:00Added an answer on June 3, 2026 at 6:25 am

    There are multiple ways to do this. I would have an array of correct questions which corresponds the questions and then compare them. For example:

    $correct_answers = array('3', '2');
    for ($i = 0; $i < $number_of_questions; $i++)
    {
       $ans_var = 'ans'.$i;
       if ($_POST[$ans_var] == $correct_answers[$i])
       {
          $score++;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php page. This has multiple images which looks like tabs. With
I have a php page like this : <html> <body> <form method=post action=catch_combo.php> <select
I have a php page that returns json like this: while ($row = oci_fetch_array($stid,
I have made a php page that sends an email message with multiple attachments.
I have a php page which has multiple form tags. each form is dealing
I'm new to javascript, my problem is effectively: I have a php page that
Suppose I have a page called view.php, if I give an argument like view.php?q=fruit,
I have a php page that has multiple iframes on the page. these iframes
function GenKeyForm(FormNum){ document.GenNewKey+FormNum.submit(); } I have multiple forms within a php page. each form
I have a PHP page with multiple mysql_query instances. Almost every one uses a

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.