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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.