Using Radio buttons in PHP Form

<html>
<body>                                  
 
<form action="mychoice.php" method="post">                                                
   <b>Enter Name:</b>           
   <input type="text" size="45" name="username">  <br>
   <b>Please select your favorite animal:</b> <br>             
   <input type="radio" name="animal" value="dog">Dog           
   <input type="radio" name="animal" value="cat">Cat
   <input type="radio" name="animal" value="fish">Fish <br>
   <input type="submit" value="Submit">
</form>            
 
</body>
</html>

File: mychoice.php

<html>
 <head>
  <title>Form submission</title>
 </head>
 <body>
 <br>
 
 <?php
  $username = $_POST['username'];
  $animal =    $_POST['animal'];
 
  if(($animal != null))
  {
    $msg = "The animal you chose is $animal <br>";
    echo($msg);
  }
 ?>
 
 </body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.