Jump to content

Recommended Posts

Hello Everybody!

I need some help as I am new into PHP.

this is my html code ..

<form name="form1" method="post" action="testingpost.php">
<p>Gender
<input name="gender" type="text" id="gender">
</p>
<p>What is your gender? </p>
<p>
<input name="mf" type="radio" value="Male">
Male
</p>
<p>
<input name="mf" type="radio" value="Female">
Female
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

I also have the php code that is testingpost.php

?php
$mf = $_POST["mf"];

print "The Gender is $gender ";
print "The Gender is $mf";

/* switch ($mf)
{
case "Male";
print "The Gender that you chose is Male";
break;
case "Female";
print "The Gender that you chose is Female";
break;
} */


//print "The Gender that you choosed is: $mf";

?>

I just would like basically when a someone choose Male or Female in the PHP I want to display it as male or female. I was trying the textfield and it worked but the radio button it doesn't.

so does anyone can help

Link to comment
https://forums.phpfreaks.com/topic/5173-get-the-value-from-htm-to-php/
Share on other sites

When ever you want to get a value that was passed from a form, you need to get it from the superglobal array. Either $_POST or $_GET depending on the method used in the form. In your case you need to use the $_POST array.

You retrieved one of the variables, but not the other.

[code]<?php
$mf = $_POST["mf"];
$gender = $_POST['gender'];  // added line

print "The Gender is $gender ";
print "The Gender is $mf";

?>[/code]

Ken
this is how i would

[code]

if($_POST['mf']==Male){
echo " you are a Male";
}
else
{
echo " you are a Female";
}

[/code]

or i do it this way

[code]

if($_POST['mf']==Male){
echo " you are a Male";
}
if($_POST['mf']==Female){
echo " you are a Female";
}

[/code]

and both of those ways have always worked fine for me
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.