ali_2kool2002 Posted March 10, 2007 Share Posted March 10, 2007 hi how do i post the below code of a radio button as the name is a variable called $button_name? <td align="center"><input type="radio" name='.$button_name.' value = '.$orderId.' unchecked> Selected</td> The line below doesnt seem to be takin the value to the other page, iv tried " " around the variable but dont work? $_POST['$button_name']; Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/ Share on other sites More sharing options...
ali_2kool2002 Posted March 10, 2007 Author Share Posted March 10, 2007 HANDLE CODE USED TO CHECK -- IN CASE U NEED IT TO HELP ME? <?php require_once('mysql_connect.php'); if (isset($_POST['submit'])) { $x = 0; if ( ! empty ( $_POST['$button_name'] ) ){ $x = $_POST['$button_name']; echo "$x"; } else { echo "empty"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/#findComment-204325 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 $_POST[$button_name]; Where is the $button_name being set in this? I do not see it called before hand, meaning that $button_name probably is nothing. You need to define that name on this page somewhere. If you do have it defined than remove the single quotes and just use $button_name. <?php require_once('mysql_connect.php'); if (isset($_POST['submit'])) { $x = 0; if ( ! empty ( $_POST[$button_name] ) ){ $x = $_POST[$button_name]; echo "$x"; } else { echo "empty"; } } ?> --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/#findComment-204328 Share on other sites More sharing options...
ali_2kool2002 Posted March 10, 2007 Author Share Posted March 10, 2007 i have defined it but stil says its empty , i check aswel with echo to see if there is a value in $button_name and there is one value $i=0; while($i<$count && $results = mysql_fetch_array($result, MYSQL_ASSOC)){ $button_name = "name".$i; $orderId = $results['orderId']; echo '<tr><td align="center">' . $results['orderId'] . '</td><td align="center">' . $results['order_status'] . '</td><td align="center">' . $results['comments'] .'</td> <td align="center">' . $results['customerId'] .'</td> <td align="center">' . $results['orderDate'] .'</td> <td align="center"><input type="radio" name='.$button_name.' value = '.$orderId.' unchecked> Selected</td> </tr> '; $i++; } echo"$button_name"; $_POST[$button_name]; echo '</table>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/#findComment-204351 Share on other sites More sharing options...
ali_2kool2002 Posted March 10, 2007 Author Share Posted March 10, 2007 FROST MASTERED IT!! WAHEY!! gud on him Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/#findComment-204364 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 You should post the end result here for everyone else to see, as I lost it. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/#findComment-204366 Share on other sites More sharing options...
ali_2kool2002 Posted March 10, 2007 Author Share Posted March 10, 2007 Ok so everytime you run the code it overwrites button_name, it needs to be an array since you can have multiple button_names. Here is one solution: Code: $i=0; // everytime this iterates it overwrites $button_name. Here is a workaround while($i<$count && $results = mysql_fetch_array($result, MYSQL_ASSOC)){ $button_name[$i] = "name".$i; // make $button_name an array $orderId = $results['orderId']; echo '<tr><td align="center">' . $results['orderId'] . '</td><td align="center">' . $results['order_status'] . '</td><td align="center">' . $results['comments'] .'</td> <td align="center">' . $results['customerId'] .'</td> <td align="center">' . $results['orderDate'] .'</td> <td align="center"><input type="radio" name='.$button_name[$i].' value = '.$orderId.' unchecked> Selected</td> </tr> '; $i++; } echo"$button_name"; foreach ($button_name as $but_name) { print $_POST[$but_name]; echo '</table>'; } } } Another is this: Code: <?php foreach ($_POST as $key => $val) { // only select post data where "name" is in the key. (for button name) if (ereg("name", $key)) { print $key . " is equal to " . $val; // prints the value of a button name } } ?> --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/#findComment-204376 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.