firedrop84 Posted March 17, 2006 Share Posted March 17, 2006 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 More sharing options...
kenrbnsn Posted March 17, 2006 Share Posted March 17, 2006 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 lineprint "The Gender is $gender ";print "The Gender is $mf";?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/5173-get-the-value-from-htm-to-php/#findComment-18372 Share on other sites More sharing options...
shortj75 Posted March 19, 2006 Share Posted March 19, 2006 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 Link to comment https://forums.phpfreaks.com/topic/5173-get-the-value-from-htm-to-php/#findComment-18750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.