Jump to content

Get the value from htm to php


firedrop84

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

Archived

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

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