0

I am doing a online test I fetch question and option from database.... I need to select which option they choosed and question id....to the next page for the answered question or not.....I got only they selected option I need get all value....

my php code as follows

 <tr>
    <td height="30"><?= $id?></td>
    <td height="30" colspan="2"><?= $question ?></td>
  </tr>

   <?php 
      if($option1!='') { ?>

  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"  value="<?php echo $id?>-<?php echo $option1?>" /></td>
    <td height="30" colspan="2"><?= $option1?></td>
  </tr>
  <?php }?>
  <?php if($option2!='') {?>
  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"    value="<?php echo $id?>-<?php echo $option2?>" /></td>
    <td height="30" colspan="2"><?= $option2?></td>
  </tr><?php }?>
  <?php if($option3!='') {?>
  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"    value="<?php echo $id?>-<?php echo $option3?>"  /></td>
    <td height="30" colspan="2"><?= $option3?></td>
  </tr><?php }?>
   <?php if($option4!='') {?>
  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"    value="<?php echo $id?>-<?php echo $option4?>"  /></td>
    <td height="30" colspan="2" ><?= $option4?></td>
  </tr>

 <?  }
2
  • so when you look at the $_POST or $_GET what do you get Commented Nov 29, 2010 at 14:33
  • I'm sorry, I just don't understand the question. Commented Nov 29, 2010 at 14:42

2 Answers 2

1

$id will have the same value for all your options.

So you might want to put name="answer" instead:

<input type="radio" name="answer" value="<?php echo $id?>-<?php echo $option2?>" />

On your result page $_GET['answer'] should then have the correct value.

Sign up to request clarification or add additional context in comments.

Comments

0

You could send all the answers as hidden elements:

<input type="hidden" name="allanswers[]" value="Answer 1" />
<input type="hidden" name="allanswers[]" value="Answer 2" />
<input type="hidden" name="allanswers[]" value="Answer 3" />
<input type="hidden" name="allanswers[]" value="Answer 4" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.