Jump to content

[SOLVED] Can't figure out how to get radio box value?


brent123456

Recommended Posts

$output .=     '<td class="highlight">Accept:<input type="radio" name=' . 
$row['trade_id'] . 'value="accepted" />Decline:<input type="radio" name=' . $row['trade_id'] . 'value="accepted" /></td>';

                                           

 

I am not sure how I can get this value on my submit page? How can I know which radio box was used the accepted box or the Decline box. It is printing this out for each trade that id in the database. There is a set of two radio buttons for each trade row. I then want to go though each set of two radio buttons on the submit page and update depending on which one was selected. Please help thanks.

Ha ha.. nope I just double posted. I did figure it out though here is the code..

 

foreach($_POST as $name=>$val)
               {
               		
                    
                    if ($val == 'accepted') {
						$query = "UPDATE my_table SET i_accepted='1' WHERE the_id='$name'";

						$result = mysql_query($query) or die("Error Processing $name"); 

		    		}
                   }
                         

Ha ha.. nope I just double posted. I did figure it out though here is the code..

 

foreach($_POST as $name=>$val)
               {
               		
                    
                    if ($val == 'accepted') {
						$query = "UPDATE my_table SET i_accepted='1' WHERE the_id='$name'";

						$result = mysql_query($query) or die("Error Processing $name"); 

what about that???

		    		}
                   }
                         

You don't need to loop through radio buttons. Only one can be selected and that's the value that you will get.

 

<?php
if (isset($_POST['accepted'])) {
    echo 'Accepted : ' . $_POST['accepted'];
}
?>
<form method='post'>
    <?php
        for ($rb=1; $rb<=5; $rb++) {
             echo "<input type='radio' name='accepted' value='$rb'> Button $rb <br/>";
        }
    ?>
    <input type='submit' name='submit' value='Submit'>
</form>

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.