Handling Radio Button Data With PHP

Make a Selection




The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../styles.css">
    <title>Radio Buttons</title>
</head>
<body>
    <h1>Handling Radio Button Data With PHP</h1>
<h4>Make a Selection</h4>
<?php

$message = '';
$language = $_POST['language'];

    if(isset($_POST['submit'])){
        if($language == 'php'){
            $message = "You have selected PHP";
        } 
        else if($language == 'html'){
            $message = "You have selected HTML";
        } 
        else if($language === 'javascript'){
            $message = "You have selected Javascript";
        } 
        else {
            $message = "Selection Required";
        }
    }
?>

<form action="index.php" method="post">
    <label for="language">
        <input type="radio" name="language" id="html" value="php">PHP <br>
        <input type="radio" name="language" id="php" value="html">HTML <br>
        <input type="radio" name="language" id="javascript" value="javascript"> JavaScript <br>
    </label>
    <br>
    <input type="submit" value="Submit" name="submit">
</form>

<h3><?php echo $message; ?></h3>
<hr>
<?php
    include('../show_code.php');
    show_code('index.php');
?>
</body>
</html>