Jump to content

post multiple radio buttons


123guy

Recommended Posts

so I think I have a good start to this, but my goal here is that I pull a bunch of data from the database, with some radio buttons pre selected, using the id in the name to make it unique so that the buttons does infact actually select.

<form action="photo.php" method="post" name="area">


<?php 


$result = mysql_query("SELECT * FROM images");


while($row = mysql_fetch_array($result))
 {
  $image1 = $row['image'];
  $area = $row['area'];
  $id = $row['id'];
?>
 <table width="266">

   <tr>
   <td width="103">
   <img src="../<?php echo $image1; ?>" width="100" /><input name="id" type="hidden" value="<?php echo $id; ?>" />
</td>
     <td width="83">Area 1<label>
       <input type="radio" name="RadioGroup<?php echo $id; ?>" value="1" id="RadioGroup1_0<?php echo $id; ?>" <?php if($area == "1"){ echo "checked=\"checked\""; }?>/>
       </label></td>

     <td width="64">Area 2<label>
       <input type="radio" name="RadioGroup<?php echo $id; ?>" value="2" id="RadioGroup1_1<?php echo $id; ?>" <?php if($area == "2"){ echo "checked=\"checked\""; }?>/>
       </label></td>
   </tr>
       </table>


<?php
 }

 ?>
 <input name="submit" type="submit" value="save" />
 </form>

 

I need help posting each radio button to the database I have set up though. Currently, I can't get the area to display the value of the radio button.

 

if($_POST['submit']){
foreach($_POST["id"] AS $key => $val) {
$id = $val;


$area = $_POST['RadioGroup'.$id.''];



mysql_query("UPDATE images SET area='$area'
WHERE id='$id'");



}
}

 

hopefully this makes some sort of sense to you. I think I am close, but I may not be, and it may be something obvious that I just can't seem to find. any help is greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/274510-post-multiple-radio-buttons/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.