Jump to content


Photo

passing data of radio button


  • Please log in to reply
4 replies to this topic

#1 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 08 April 2006 - 06:10 AM

radio.php
<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>


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

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

#2 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 08 April 2006 - 06:24 AM

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.

#3 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 08 April 2006 - 06:32 AM

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

#4 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 08 April 2006 - 06:37 AM

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:

<input type="radio" name="answer" value="<? echo $name; ?>">


#5 klinmy

klinmy
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 08 April 2006 - 06:42 AM

yea thanks alot khendar! it works now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users