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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:49:06+00:00 2026-06-15T23:49:06+00:00

please help, i’m developing an online quiz application. All the questions and answers will

  • 0

please help, i’m developing an online quiz application. All the questions and answers will be selected from the database. Where i’m having probkem with is to get the values from the radio button whether checked or not. bellow is the code that generate the questions and answers from database.

if (!isset($_POST['submit'])) {
    echo "<form method=post action='#'>";
    echo "<table border=0>";
    while ($row = mysql_fetch_array($display)) {
        $id = $row["id"];
        $question = $row["question"];
        $opt1 = $row["ans1"];
        $opt2 = $row["ans2"];
        $opt3 = $row["ans3"];
        $opt4 = $row["ans4"];
        $opt5 = $row["ans5"];
        $answer = $row["ans"];
        echo "<tr><td colspan=3><br><b>$question</b></td></tr>";
        echo "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2     <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td><td>$opt4 <input type=radio name=q$id value=\"$opt4\"></td><td>$opt5 <input type=radio name=q$id value=\"$opt5\">q$id</td></tr>";
    }
    echo "</table>";
    echo "<input type='submit' value='See how you did' name='submit'>";
    echo "</form>";
}

the name of the radio button is

<input type='radio' name='q$id' value='$opt4' />

How do i get the value of the checked radio button?
or is my PHP code wrong?
what i needed is to output what is selected if a radio button is checked.

if(isset($_POST['submit']))
{
    $value = $_POST[''];//the value of the radio button, i don't know what to put here
    $n = count($value);
   for($i=0; $i < $n; $i++)
   {
     echo $value[$i];
   } 
}
  • 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-15T23:49:07+00:00Added an answer on June 15, 2026 at 11:49 pm

    Try:

    if(isset($_POST['submit']))
    {
        $value = $_POST;//the value of the radio button, i don't know what to put here
        $n = count($value);
       for($i=0; $i < $n; $i++)
       {
         echo $value[$i];
       } 
    }
    

    $_POST[”] was wrong. You needed to use just $_POST.

    You could also just use foreach here:

    if(isset($_POST['submit']))
    {
        $values = $_POST;//the value of the radio button, i don't know what to put here
    
       foreach($values as $value)
       {
         echo $value;
       } 
    }
    

    $_POST is just a array containing whatever your form submited. If you had a name textfield you would use:

    echo $_POST['name'];
    

    to echo it.

    Try

    var_dump("<PRE>", $_POST);
    

    And you will see exactly how your form is being organised. Link to documentation

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

Sidebar

Related Questions

Please help me. As i am not getting the selected index from the c#
Please help me I'm developing an android application to display a pinch zoom-able and
please help me out from this I have created a database in Blackberry phone
Please help me to figure this out. I am having two tab bar items
Please help me understand, the below code is showing Type mismatch: cannot convert from
Please help I am trying to code for selectAll or clear all using Jquery.
Please help me the code (Java) to encrypt and decrypt ( will be better
please help me. I want to print some reports from .NET app. I read
Please help. I've got an error while deserializing the data from the server, The
Please help me find a way to embed the relational views of a database

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.