Write a PHP script for arithmetic operation use radio buttons | PHP - IProgramX

Q. Write a PHP script for the following: Design a form to accept two numbers from the user. Give options to choose the arithmetic operation (use radio buttons). Display the result on the next form. (Use the concept of function and default parameters. Use ‘include’ construct or require stmt)



HTML File:

<html>
        <body bgcolor=pink >
            <form action="ass1b1.php" method= "GET" >
            Enter first number :  <input type=text name=a ><br>
            Enter second number:  <input type=text name=b ><br>
                                                                                                                             
        Operation::
                <input type=radio name=c value=1>Addition.<br>
                <input type=radio name=c value=2>Subtraction.<br>
                <input type=radio name=c value=3>Multiplication.<br>
                <input type=radio name=c value=4>Division.<br>
        <input type=submit value=ok>    <input type=reset value=clear>
        </form>
        </body>

 </html>

PHP Function:
NOTE: PHP function is saved as "ass1b1.php"


<?php
$n1 = $_GET['a'];
$n2 = $_GET['b'];
$ch = $_GET['c'];

        if($ch==1)
        {
            $c = $n1 + $n2;
            echo"addition is: $c"; 
        }
        else if($ch==2)
        {
            $c = $n1 - $n2; 
            echo"subtraction is: $c";
        }
        else if($ch==3)
        {
            $c = $n1 * $n2; 
            echo"multiplication is: $c";
        }
        else if($ch==4)
        {
            $c = $n1 / $n2; 
            echo"Division is: $c";
        
        }
?>

Output:






Post a Comment

1 Comments

  1. question also says "Use ‘include’ construct or require stmt" where is that??

    ReplyDelete