Post array

I wanna post the value of qid and $row[‘quest_id’] value but i get the error “Notice: Undefined offset: 1 in …”? What’s wrong with my code? anyone can help me?

<tr><th><input type="text" value="<?php echo ''.$row['quest_id'].''; ?>" name="qid[]"/></th></tr>
<tr><td><input type="radio" name="<?php echo ''.$row['quest_id'].''; ?>[]" value="opt1"/>'.$row['opt1'].'</td></tr>
<tr><td><input type="radio" name="<?php echo ''.$row['quest_id'].''; ?>[]" value="opt2"/>'.$row['opt2'].'</td></tr>
<tr><td><input type="radio" name="<?php echo ''.$row['quest_id'].''; ?>[]" value="opt3"/>'.$row['opt3'].'</td></tr>
<tr><td><input type="radio" name="<?php echo ''.$row['quest_id'].''; ?>[]" value="opt4"/>'.$row['opt4'].'</td></tr>


for($i=0; $i<count($q) ;$i++)
   echo "quest_id = $q[$i]<br>";
   echo "user_ans = $c[$i]<br><br>";

is ‘quest_id’ numeric?

quest_id is integer…

Variables in PHP must start with a letter or underscore… i’m not sure if HTML passes them correctly or not
Try putting a letter in front of those form variables.


echo “user_ans = $c[$i]<br><br>”;

fairly sure that’s your problem.
$i has no bearing on $c.
$c should only contain 1 value…

if I remove $i, the result become “user_ans = Array”…

There’s a couple of things that are wrong here:

  1. Radio buttons don’t need to be an array, only the checked value is sent to the server.

  2. Your radio buttons don’t have a valid name, and all the buttons in one set should have the same name.

  3. $_POST[‘qid’] contains the value of the text input, and you’re trying to loop through it as though it’s an array. Although that will work technically, it’s not what you mean to do in this case (I think)

Can you describe exactly what you’re trying to achieve? Maybe we can help you write some working code :slight_smile:

yaya… I found my problem already…
I want to use ‘quest_id’ as name of my radio button…
after I remove the array from my radio button I get what I want…
Thanks all…