Jump to content

Archived

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

firedrop84

Get the value from htm to php

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

Share this post


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

Share this post


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

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.