How to Get Input From Radio Button in PHP

How to get input from radio button in php - In the input of the radio button type, the user can only choose one option among several options. To understand more about how to get input from the radio button in php, then here I give examples of the program.
Program 1
File Name: input06.php
Description: The program displays the department's preferred form with the radio button.
Open notepad then type the following html code.
<html>
<head><title>Select Major</title></head>
<body>
  <FORM ACTION="process06.php" METHOD="POST" NAME="input">
   <h2>Choose Your School :</h2>
   <input type="radio" name="Majors" value="TI" checked> Technical Information<br>
   <input type="radio" name="Majors" value="IS"> Information Systems<br>
   <input type="radio" name="Majors" value="CS"> Computer System<br>
   <input type="radio" name="Majors" value="CA"> Computerized Accounting<br>
   <input type="submit" name="choose" value="choose">
</FORM>
</body>
</html>

How to Get Input From Radio Button in PHP

Save the code in the notepad earlier in the htdocs folder with the name input06.php
Program 2
File Name: process06.php
Description: Program to pick and display selected majors in program 1.
You open notepad then input the following code.
<?php
if (isset($_POST['choose'])) {
 $Majors = $_POST['Majors'];
 echo "Your department is
<b><font color='red'>$Majors</font></b>";
}
?>

How to Get Input From Radio Button in PHP

Save the code into the htdocs folder named process06.php.
Explanation of Programs 1 and 2
Program 1 will display the option form the direction of the direction with the radio button (see picture). In the form of input radio button, the name of each radio button must be the same, but the value must be differentiated. Pay attention to program 1 line 6-9! To retrieve the value (value) of the form radio type, can directly by accessing the name of the form. Watch the 2nd row program!
To run the program, open the browser then in the address bar type http://localhost/input06.php. Then the result will look like the following.
How to Get Input From Radio Button in PHP
Program View

How to Get Input From Radio Button in PHP
Program View

Hopefully the tutorial on How to Get Input From Radio Button in PHP can improve our ability to learn the php programming language. Learn also the tutorial on How to Make Login Form in PHP.

Comments