Sunday, 7 January 2018

How To Get Radio Button Value In PHP?

Step 1:

Start the XAMPP server
Click on the "Start" button next to "Apache" to start your Apache Web server and also start "MySQL"

Step 2:
Create Radio.html

<!doctype html>
<html lang="en:US">
<head>
<meta charset="UTF-8">
<title>Get RadioButton Value</title>
</head>

<body>
<form method="post" action="rad.php">

Gender:</br>
<input type ="radio" name="gender" value="Male" checked>Male</br>
<input type ="radio" name="gender" value="Female">Female</br>
<input type ="radio" name="gender" value="Other">Other</br>

<input type="submit" name="submitbtn" value="Click"/>

</form>
</body>
</html>

Step 3:

Create rad.php

  <?php

    if(isset($_POST['submitbtn']))
    {
            $Gender=$_POST['gender'];
          if($Gender == "Male")
            {  
              echo("Male");
            }
           
    else if($Gender == "Female")
     {
     echo("Female");
       }
             
             else
             {
            echo("Other");
           
                }
            
          }

         ?>

Step 4 :

Save both the file(Radio.html,rad.php) in htdocs under  xampp  server in c:drive.

Step  5:

Open the browser (chrome) and type it
localhost/ Radio.html

Gender:
Male
Female
Other
 

After clicking button you can get the following output
Male

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...