Jump to content

Split: PHP/MySQL Multiple Choice Quiz Logic


tenar

Recommended Posts

Hi, sorry for bumping this thread. I have a question regarding your code. I'm pretty new to any kind of coding. In this line: 

<input type="radio" name="answer[<?php echo $result['id'] ?>]" value="A"> <?php echo $result['answerA']; ?> <br>

 

 

what is the value assigned to the name in the end. name="answer"    or     name="answer$id" or something else.

Link to comment
Share on other sites

Names would look like answer[$id]

eg

<form action="" method="get">
Q1. Do you know which?<br>
<input type="radio" name="answer[1]" value="A">A - Answer A<br>
<input type="radio" name="answer[1]" value="B">B - Answer B<br>
<input type="radio" name="answer[1]" value="C">C - Answer C<br>
<input type="radio" name="answer[1]" value="D">D - Answer D<br>
<br><br>
Q2. What is the answer?<br>
<input type="radio" name="answer[2]" value="A">A - Answer A<br>
<input type="radio" name="answer[2]" value="B">B - Answer B<br>
<input type="radio" name="answer[2]" value="C">C - Answer C<br>
<input type="radio" name="answer[2]" value="D">D - Answer D<br>
<br><br>
<input type="submit" value="Submit" name="btnSubmmit">
</form>

So when posted would look like this (depending on the answers selected)

 

Array
(
    [answer] => Array
        (
            [1] => B
            [2] => D
        )

    [btnSubmmit] => Submit
)

hope that helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.