0% found this document useful (0 votes)
2 views

Simple_Calculator_PHP_Documentation

This document outlines the creation of a simple web-based calculator using HTML and PHP, enabling users to perform basic arithmetic operations. It details the technologies used, features, and the process of user input handling and result display. The project serves as an introductory exercise in PHP development and server-side processing.

Uploaded by

Rajalakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Simple_Calculator_PHP_Documentation

This document outlines the creation of a simple web-based calculator using HTML and PHP, enabling users to perform basic arithmetic operations. It details the technologies used, features, and the process of user input handling and result display. The project serves as an introductory exercise in PHP development and server-side processing.

Uploaded by

Rajalakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Simple Calculator using PHP - Documentation Report

Introduction

This project is a basic web-based calculator implemented using HTML and PHP. It allows users to perform

four fundamental arithmetic operations: Addition, Subtraction, Multiplication, and Division.

Objective

To create a simple, interactive calculator using PHP that demonstrates the use of forms, user input

processing, and basic arithmetic operations.

Technologies Used

- Frontend: HTML, CSS (optional)

- Backend: PHP

- Server: Localhost (e.g., XAMPP, WAMP)

Features

- Addition, Subtraction, Multiplication, Division

- Form validation (basic)

- Instant result display after form submission

How It Works

1. The user enters two numbers in the input fields.

2. The user selects the operation (add, subtract, multiply, divide).

3. The form submits the data to the same page.

4. PHP code processes the input and displays the result.


Simple Calculator using PHP - Documentation Report

Source Code

<!DOCTYPE html>

<html>

<head>

<title>Simple Calculator</title>

</head>

<body>

<h2>PHP Calculator</h2>

<form method="post">

<input type="number" name="num1" placeholder="Enter first number" required>

<input type="number" name="num2" placeholder="Enter second number" required>

<select name="operator" required>

<option value="add">Add</option>

<option value="sub">Subtract</option>

<option value="mul">Multiply</option>

<option value="div">Divide</option>

</select>

<input type="submit" name="submit" value="Calculate">

</form>

<?php

if (isset($_POST['submit'])) {

$num1 = $_POST['num1'];

$num2 = $_POST['num2'];
Simple Calculator using PHP - Documentation Report

$operator = $_POST['operator'];

$result = "";

switch ($operator) {

case "add":

$result = $num1 + $num2;

break;

case "sub":

$result = $num1 - $num2;

break;

case "mul":

$result = $num1 * $num2;

break;

case "div":

if ($num2 == 0) {

$result = "Cannot divide by zero!";

} else {

$result = $num1 / $num2;

break;

echo "<h3>Result: $result</h3>";

?>

</body>
Simple Calculator using PHP - Documentation Report

</html>

Conclusion

This simple calculator demonstrates how to collect input from a user, process it using PHP, and display

results dynamically. It is a foundational exercise in PHP development and helps understand server-side

processing.

You might also like