Jump to content

How to get value from radio button in php using id?


siddscool19

Recommended Posts

<html>
<body>
<form method=get>
<input type=radio name=gender id=male >Male</br>
<input type=radio name=gender id=female >Female</br>
<input type=submit value=Submit>
</form>
</body>
</html>
<?php
$gender=$_GET["gender"];
echo $gender
?>

 

Now i want the value of only <input type=radio name=gender id=male > ..

What coding is to be used?

 

Link to comment
Share on other sites

You HAVE to add a value= to your radios otherwise they have no value

 

<input type=radio name=gender value="male" id=male >Male</br>

<input type=radio name=gender value='female" id=female >Female</br>

 

Then do this....

<?php
$gender = $_GET['gender'];
if($gender == 'male')
{
    echo 'Its a boy!!';
}
else
{
   echo 'Throw her back';
}
?>

 

Basic HTML structure and php comparison operators.

 

Nate

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.