Jump to content

passing data of radio button


klinmy

Recommended Posts

radio.php
[code]<form method="post" action="nextpage.php">
<?

$query=mysql_query("SELECT name FROM staff WHERE id='1122' ");
while ($row = mysql_fetch_array($query))
{
    echo "$row[name]";
    $name=$row[name];
    
}

?>
<input type="radio" name="answer" value="<? $_POST['name'] ?>">
<input type="radio" name="answer" value="B">

<input type="submit" name="Submit" value="Submit">
</form>[/code]


nextpage.php
[code]<? echo '1122 is  '.$_POST['name']!; ?>[/code]

when i clicked in the 1st radio button, it displayed "[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]1122 is ! [!--colorc--][/span][!--/colorc--]"
why cant it display the name as it's shown in radio.php? thanks
Link to comment
https://forums.phpfreaks.com/topic/6865-passing-data-of-radio-button/
Share on other sites

Ok....You are passing the value of $_POST['name'] as the value of the first radio button, but this radio button is not called name its called answer.

In nextpage.php you should echo $_POST['answer']; not $_POST['name'];

Also, you shouldn't use the ! symbol where it is. When ! is not inside a string it becomes a the logical operator NOT. If you want the ! to be printed out at the end of the string you should put it inside single quotes and use the . symbol to add it to the line being echoed.
Check out the html source code of your form. See if the value is being assigned to the radio button in the first place. If not it means the error is somewhere else.

I take it you want to set the value to the name from the database ?

Then you should change it to:

[code]<input type="radio" name="answer" value="<? echo $name; ?>">[/code]

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.