I would like to have several radio button to display information for a dynamic webpage. I have (in PHP):
echo '
<html>
<head>
<title> Dynamic PHP </title>
</head>
<body>
<form action="dynamic.php" method="get">
<input type="radio" name="dynamic" value="home" checked> Home </br>
<input type="radio" name="dynamic" value="site1"> Site 1 </br>
<input type="radio" name="dynamic" value="site2"> Site 2
</form>
</body>
</html>
';
if (isset($_GET["home"])){
echo "Home";
}
if (isset($_GET["site1"])){
echo "Site 1";
}
if (isset($_GET["site2"])){
echo "Site 2";
}
I don’t get any errors, but nothing happens either. Thanks a lot.
Edit: This is like what I’m asking: radio button value in php
PHP accesses form variables through their “name” attribute, not their “value” attribute. In order to retrieve the value of the selected radio button, you would use
$_GET['dynamic']and not$_GET['home']or$_GET['site1']or$_GET['site2'].So assuming this page is called dynamic.php, your code to echo the selected one would be:
Hope this helps!
EDIT: In order to echo the selected option: