Jump to content


Photo

Get the value from htm to php


  • Please log in to reply
2 replies to this topic

#1 firedrop84

firedrop84
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 17 March 2006 - 05:46 PM

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



#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 06:00 PM

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.

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

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

?>

Ken


#3 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 19 March 2006 - 07:03 AM

this is how i would


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


or i do it this way


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


and both of those ways have always worked fine for me
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users