Write a simple calculator program in PHP using switch case

How to make simple calculator program in php

Please Note some things if you are copying my.. make sure form action name same with your source code page..

Example:- my source code file name is calculator.php

Aim:- Design simple calculator using PHP

Software Requirements:- xampp server ( for Php running ), Code editor like, Vs Code, Notepad ++.


1-Create file and give the file name with .php extension ( calculator.php)

2- Copy my code, Otherwise learn about this project on YouTube and Try yourself to design this.

3-After completing your source code.. Open Xampp control panel

4-Start Apache and Mysql

5-Now, For accessing your result you have to give address of file location on any browser within your system like, Chrome, FireFox etc..

6- Your file location like:- http://localhost/1stproject/calculator.php 

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Online Calculator</title>
        border2px solid red;

    <h1>Online Calculator</h1>
    <form action="calculator.php" method="post">
        <div class="container">
            <input type="text" name="no1">
            <label for="no1">Enter 1st value</label><br>
            <input type="text" name="no2"> 
            <label for="no2">Enter 2nd value</label><br>
            <select name="mainfun" id="">
                <option value="add" name="meth">Method:  +  -  *   /</option>
                <option value="add" name="add">Addition</option>
                <option value="sub" name="sub">Subtraction</option>
                <option value="mul" name="mul">Multiplication</option>
                <option value="div" name="div">division</option>
            <input type="submit" name="subtn" value="Calculate">
    echo "<center><br> your 1st Enter number is  $num1 </center>";
    echo "<center><br> your 2nd Enter number is $num2 </center>";
    switch ($action) {
        case 'add':
            echo "<center><br>Your Addition value is</center>";
            echo "<center><br>$result </center>";
        case 'sub':
            echo "<center><br>Your Subtraction value is </center>";
            echo "<center><br>$result </center>";
        case 'mul':
            echo "<center><br>Your Multiplication value is </center>";
            echo "<center><br>$result </center>";
        case 'div':
            echo "<center><br>Your Divisible value is </center>";
            echo "<center><br>$result </center>";
            echo "Wrong Input";


how to create a calculator using html and php

simple calculaote program in php 

Write PHP script for arithmetic Scientific calculator using form

scientific calculator in php source code

create calculator using function in php

php math calculator script

simple calculator program in php using if else

php code for calculator with buttons

Post a Comment