dannyo101 Posted January 29, 2009 Share Posted January 29, 2009 I have a registration form for a tournament. A user must input a persons name & age and indicate if that person is the captian. The form will list 3 lines, 1 for each person. I want to use a radio button to indicate if the person is a captain. There can only be one captain. I the way I have it now, the value is copied for every person. Here is my code: for ( $id = 1; $id <= 5; $id += 1) { echo '<tr><td>'; echo '<input type="hidden" name="p_id['.$id.']" value="'.$id.'">'.$id; echo '</td><td>'; echo '<input name="fname['.$id.']" type="text" maxlength="20" id="fname['.$id.']" size="20">'; echo '</td><td>'; echo '<input name="lname['.$id.']" type="text" maxlength="20" id="lname['.$id.']" size="20">'; echo '</td><td>'; echo '<input type="radio" name="captain" id="captain['.$id.']" value="Y">'; echo '</td></tr>'; } Here is how I'm posting the variables: foreach($_POST['id'] as $f_id){ $p_id=$_POST['p_id'][$f_id]; $fname=$_POST['fname'][$f_id]; $lname=$_POST['lname'][$f_id]; } $cpt=$_POST['captain']; for ($i = 1; $i <= count($p_id); ++$i){ echo '<tr><td>'; echo $i; echo '</td><td>'; echo $fname[$i]; echo '</td><td>'; echo $lname[$i]; echo '</td><td>'; echo $cpt; echo '</td></tr>'; } Quote Link to comment https://forums.phpfreaks.com/topic/142920-multiple-radio-buttons/ Share on other sites More sharing options...
Mchl Posted January 29, 2009 Share Posted January 29, 2009 Value attribute for each radio should be different. See example: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio Quote Link to comment https://forums.phpfreaks.com/topic/142920-multiple-radio-buttons/#findComment-749381 Share on other sites More sharing options...
dannyo101 Posted January 30, 2009 Author Share Posted January 30, 2009 Even when I set the value attribute for each radio button to be different, the value is duplicated in my results. I set the radio button to this: echo '<input type="radio" name="captain" id="captain" value="'.$id.'">'; In my results, the same number is duplicated. I think the problem is with how I'm handling the $_POST. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/142920-multiple-radio-buttons/#findComment-750327 Share on other sites More sharing options...
zhangy Posted February 1, 2009 Share Posted February 1, 2009 Even when I set the value attribute for each radio button to be different, the value is duplicated in my results. I set the radio button to this: echo '<input type="radio" name="captain" id="captain" value="'.$id.'">'; In my results, the same number is duplicated. I think the problem is with how I'm handling the $_POST. Any thoughts? bleh, dunno Quote Link to comment https://forums.phpfreaks.com/topic/142920-multiple-radio-buttons/#findComment-751952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.