Jump to content

Archived

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

klinmy

passing data of radio button

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
thanks khendar,
i've change the name to answer as u taught, and canceled off the '!', but it's still the same..

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.