Slip no.19. Write a PHP script for the following:
a) Design a form to accept two numbers from the users.
b) Give option to choose an arithmetic operation ( use Radio Button).
c) Display the result on next form.
d) Use concept of default parameter.
HTML file :
<FORM ACTION="slip19_2.php" method="GET">
<tr><td><h3>Enter first no :</td><td><input type=text name=no1  ></h3></td></tr>
<tr><td><h3>Enter second no :</td><td><input type=text name=no2></h3></td></tr>
<tr><td><b>Select Operation which u have to perform :</b></td></tr>
                <tr><td><input type=radio value="1" name=cal>Addition</td></tr>
                <tr><td><input type=radio value="2" name=cal>Substraction</td></tr>
                <tr><td><input type=radio value="3" name=cal>Multiplication</td></tr>
                <tr><td><input type=radio value="4" name=cal>Division</td></tr>              
<tr><td></td><td><input type=submit name=submit value=Calculate></td></tr>

PHP file :
                $no1 = $_GET['no1'];
                $no2 = $_GET['no2'];
                $cal =$_GET['cal'];
$add = $no1+$no2;
echo "<h1>addition = ".$add."</h1>";
else if($cal == 2)
$sub = $no1-$no2;
echo "<h1>subtraction = ".$sub."</h1>";
       else if($cal == 3)
$mult = $no1*$no2;
echo "<h1>multiplication = ".$mult."</h1>";
else if($cal == 4)
$div = $no1/$no2;
echo "<h1>division = ".$div."</h1>";

No comments:

Post a comment

Note: only a member of this blog may post a comment.