I created a basic website that requires the user to select a radio button. I want the PHP file to retrieve the value of the switch that was selected and respond appropriately, but currently the file does not produce any output. What is wrong with the code I'm using now? Why can't my PHP file get the switch value correctly?
Index.html:
<form method="POST"> <input type="radio" name="MyRadio" value="First" checked>First<br> //This one is automatically checked when the user opens the page <input type="radio" name="MyRadio" value="Second">Second </form> <form method="GET" action="Result.php"> <input type="submit" value="Result" name="Result"> //This button opens Result.php </form>
Result.php:
<?php $radioVal = $_POST["MyRadio"]; if($radioVal == "First") { echo("You chose the first button. Good choice. :D"); } else if ($radioVal == "Second") { echo("Second, eh?"); } ?>
user4721723
source share