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

PHP_exp1_62

This document outlines an experiment to create a PHP script that performs basic arithmetic operations (addition, subtraction, multiplication, and division) based on user input. It includes the aim, course outcomes, learning objectives, related theory about PHP, code implementation, execution steps, and a conclusion on the successful demonstration of dynamic arithmetic operations. The experiment emphasizes understanding PHP syntax and user input handling.

Uploaded by

abhijit.17506
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)
1 views

PHP_exp1_62

This document outlines an experiment to create a PHP script that performs basic arithmetic operations (addition, subtraction, multiplication, and division) based on user input. It includes the aim, course outcomes, learning objectives, related theory about PHP, code implementation, execution steps, and a conclusion on the successful demonstration of dynamic arithmetic operations. The experiment emphasizes understanding PHP syntax and user input handling.

Uploaded by

abhijit.17506
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

Experiment No.

- 1

Date of Performance: 8/1/25

Date of Submission:

Program Execution/
formation/ Timely
Viva Experiment
correction/ Submission Sign with Date
(03) Total (10)
ethical practices (01)
(06)
Experiment No. - 1

PHP Script to Perform Simple Arithmetic Operations and Display the Result

1.1 Aim:

To develop a PHP script that performs basic arithmetic operations (addition, subtraction,
multiplication, and division) and displays the results dynamically.

1.2 Course Outcome:

Understand and apply fundamental programming concepts in PHP to execute arithmetic


operations and generate output dynamically.

1.3 Learning Objective:

●​ To learn the syntax and basic operations in PHP.


●​ To implement user input handling and perform arithmetic calculations.
●​ To display the results of arithmetic operations in a structured manner.

1.4 Related Theory:

What is PHP? PHP (Hypertext Preprocessor) is a widely used open-source server-side scripting
language primarily designed for web development. It can be embedded within HTML and is
executed on the server to generate dynamic web pages.

Features of PHP:

●​ Open-source and platform-independent.


●​ Supports various databases like MySQL, PostgreSQL, and SQLite.
●​ Provides built-in support for handling forms and user input.
●​ Capable of handling sessions and cookies for state management.
●​ Has extensive libraries for file handling, image processing, and encryption.

Arithmetic Operations in PHP: PHP supports basic arithmetic operations, which include:

●​ Addition (+): Adds two numbers.


●​ Subtraction (-): Subtracts one number from another.
●​ Multiplication (*): Multiplies two numbers.
●​ Division (/): Divides one number by another and returns the quotient.
●​ Modulus (%): Returns the remainder of a division operation.
1.5 PHP Code Implementation:
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Operations in PHP</title>
</head>
<body>
<h2>PHP Arithmetic Operations</h2>
<form method="post">
Enter first number: <input type="number" name="num1" required><br>
Enter second number: <input type="number" name="num2" required><br>
<input type="submit" name="calculate" value="Calculate">
</form>

<?php
if(isset($_POST['calculate'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];

echo "<h3>Results:</h3>";
echo "Addition: " . ($num1 + $num2) . "<br>";
echo "Subtraction: " . ($num1 - $num2) . "<br>";
echo "Multiplication: " . ($num1 * $num2) . "<br>";
if ($num2 != 0) {
echo "Division: " . ($num1 / $num2) . "<br>";
echo "Modulus: " . ($num1 % $num2) . "<br>";
} else {
echo "Cannot divide by zero.";
}
}
?>
</body>
</html>

1.6 Execution Steps:

1.​ Install a local server like XAMPP or WAMP.


2.​ Create a PHP file (arithmetic.php) and paste the above code.
3.​ Place the file inside the htdocs folder (for XAMPP) or the www folder (for WAMP).
4.​ Start the Apache server from the XAMPP/WAMP control panel.
5.​ Open a web browser and visit http://localhost/arithmetic.php.
6.​ Enter two numbers in the input fields and click "Calculate" to see the results.

1.7 Output:

1.8 Conclusion:

By implementing this PHP script, we have successfully demonstrated how to perform basic
arithmetic operations dynamically using user inputs. This experiment enhances our
understanding of PHP scripting, form handling, and server-side execution.

You might also like