Jump to content

[SOLVED] radio button to post variable ?


ali_2kool2002

Recommended Posts

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'];

Link to comment
https://forums.phpfreaks.com/topic/42126-solved-radio-button-to-post-variable/
Share on other sites

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";
}

}


?>

$_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

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>';

}
}
?>

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

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.