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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:16:31+00:00 2026-05-29T17:16:31+00:00

OK this is my script:- <form action=results.php method=post> <?php mysql_select_db($database, $databasename) or die(Opps some

  • 0

OK this is my script:-

<form action="results.php" method="post">
          <?php mysql_select_db($database, $databasename) or die("Opps some things went wrong");
          $sqlQueryTestDisplay = mysql_query("SELECT * FROM questions WHERE test_id='$testtaken_id' ORDER BY question_id ASC");
          $i = 0;
          while($DisplayItems = mysql_fetch_array($sqlQueryTestDisplay))
          {
              $i = $i + 1;
              $question_id = $DisplayItems['question_id'];
              $question = $DisplayItems['question'];
              $opta = $DisplayItems['opta'];
              $optb = $DisplayItems['optb'];
              $optc = $DisplayItems['optc'];
              $optd = $DisplayItems['optd'];
              $answer[$i] = $DisplayItems['answer'];
              $thisAnswer = $answer[$i];
              echo '<li>'.$question.'</li>';
              echo '<p>';
              echo '<label><input type="radio" name="optans'.$i.'" value="radio" id="RadioGroup'.$i.'_0" />'.$opta.'</label>';
              echo '<label><input type="radio" name="optans'.$i.'" value="radio" id="RadioGroup'.$i.'_1" />'.$optb.'</label>';
              echo '<label><input type="radio" name="optans'.$i.'" value="radio" id="RadioGroup'.$i.'_2" />'.$optc.'</label>';
              echo '<label><input type="radio" name="optans'.$i.'" value="radio" id="RadioGroup'.$i.'_3" />'.$optd.'</label>';
              echo '<input name="ans'.$i.'" type="hidden" value="'.$thisAnswer.'" />';
              echo '</p>';
          }
          echo '<input name="total_questions" type="hidden" value="'.$i.'" />';
          echo '<input name="test_id" type="hidden" value="'.$TestID.'" />';
          ?>
          <input name="submittest" type="submit" />
          </form>

As you can see i am using array to store values in different fields. Now on the next page i.e on my result.php page I am writing this:-

<?php
if(isset($_POST['submittest'])) 
{
global $ans1;
$TotalQuestions = $_POST['total_questions'];
$TestID = $_POST['test_id'];
$TestResult = 0;
for ($i=1; $i<=$TotalQuestions; $i++)
{
    $ansValue = 'ans'.$i;
    $optansValue = 'optans'.$i;
    $ans = $_POST[$ansValue];
    $optans = $_POST[$optansValue];
    if ($ans == $optans)
    {
        $TestResult = $TestResult + 1;
    }
}
$st_id = $row_Recordset1['id'];
mysql_select_db($database, $databasename) or die("Opps some things went wrong");
$sqlQueryInsertResult = mysql_query("INSERT INTO results (student_id, test_id, test_result) VALUES ('$st_id', '$TestID', '$TestResult')");
header('location:results.php'); 
}
?>

Now my script is not reading ans1, ans2…..and so on AND even quesans1, quesans2…..and so on.

I think problem is in the way i am calling the array using the $_POST method.

Is the syntax correct, how can i FIX it… Please help 😐

  • 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-29T17:16:33+00:00Added an answer on May 29, 2026 at 5:16 pm

    All of your radio buttons are returning “radio” as their value. Make them return the answer and you should be OK
    Change your radio definitions to:

    '<INPUT type="radio" name="optans'.$i.'" value="'.$opta.'" >'.$opta.'</INPUT>'
    '<INPUT type="radio" name="optans'.$i.'" value="'.$optb.'" >'.$optb.'</INPUT>'
    '<INPUT type="radio" name="optans'.$i.'" value="'.$optc.'" >'.$optc.'</INPUT>'
    '<INPUT type="radio" name="optans'.$i.'" value="'.$optd.'" >'.$optd.'</INPUT>'
    

    Might be worth not putting the answer onto the page as a hidden field – makes a quiz quite easy. Do another SQL query to check the answers when they come back

    Use some more loops to display the radio buttons and you can shorten your code a bit.

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

Sidebar

Related Questions

I've attached onsubmit handler in a form tag like this: <form action=file.php method=post onsubmit=
External form <form action=MyForm.action method=post> hosted on a different server. I want my PHP
I have the following form that has 2 selects: <form id=form class=form_visitar method=post action=ajax/selects.php>
Let's say I have the following scenario: <form action=/something.php method=GET>Click me</div> <script type=text/javascript><!-- $('form').submit(function(e)
I've created a search form for a script in php. Basicaly this form have
I have this little script to toggle a contact form when a button is
I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
I got this script called rapidshare link checker v2 php by Bigfish At the
This question is relating to 2 php scripts. The first script is called pick_modcontact.php
I am looking for some help. I have found this script that sort of

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.