Write a PHP program to create a simple calculator that can accept two numbers and perform operations like add, subtract, multiplication and divide (using Self Processing form)

Calculator.php
<HTML>
<BODY>
<FORM method=POST action="<?php echo $_SERVER['PHP_SELF'] ?>">
Enter   First   Value  :<INPUT type=text name=a><BR><BR>
Enter Second Value:<INPUT type=text name=b><BR><BR>
<b>Select Arithmetic Operation</b><BR><BR>
<INPUT type=radio name="choice" value="1">Addition<BR><BR>
<INPUT type=radio name="choice" value="2">Subtraction<BR><BR>
<INPUT type=radio name="choice" value="3">Multiplication<BR><BR>
<INPUT type=radio name="choice" value="4">Division<BR><BR>
<INPUT type=submit name=submit value="Calculate"><BR>
</FORM>
<?php
         $c="";
if(isset($_POST['submit']))
         {
           $a=$_POST['a'];
           $b=$_POST['b'];
           $ch=$_POST['choice'];
if($ch=='1')
           {
            $c=$a+$b;
echo"Addition =  $c";
           }
if($ch=='2')
           {
            $c=$a-$b;
echo"Subtraction =  $c";
           }
if($ch=='3')
           {
            $c=$a*$b;
echo"Multiplication =  $c";
           }
if($ch=='4')
           {
            $c=$a/$b;
echo "Division =  $c";
           }
         }
?>
</BODY>
</HTML>

Comments

Popular posts from this blog

Create an XML file which gives details of books available in “ABC Bookstore” from following categories. 1)      Technical 2)      Cooking 3)      Yoga And elements in each category are in the following format.     …….     …….     ……. Save the file as “Book.xml” Create an application that reads “Book.xml” file into simple XML object. Display attributes and elements. (Hint:- Use simple_xml_load_file() function). 

Write a script to solve following questions(use “Book.xml” file) A:- Create a Dom document object and load this xml file. B:- Get the output of this document to the browser. C:- Save this [.xml] document in another format that i.e. in [.doc]. D:- Write a xml program to print the names of the books available in “Book.xml” file.