TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

PHP

PHP Program to Add Two Numbers

Introduction

In this post, we will learn how to add two numbers using PHP. Sample PHP Program is the given below to get the sum of the two numbers a and b.

PHP Project

I would be using Eclipse with PDT installed. Create a New PHP Project in Eclipse.

New >> PHP Project.

 

PHP file

Create a new PHP file under the project created.

New >> New PHP file.

 

Add PHP Code

Add PHP code to the file as shown below:

<html>

<head>

<title>Addition of Numbers</title>

</head>

<body>



<form action="" method="post">

<label>Enter a:</label>

<input type="text" name="a" />

<br>

<br>

<label>Enter b:</label>

<input type="text" name="b" />

<br>

<br>

<input type="submit" name="Sum" value="Add a+b">

</form>



<?php

if(isset($_POST['Sum']))

{

$a = $_POST['a'];

$b = $_POST['b'];



$total = $a +$b;



echo "The value of a + b=".$total;

}

?>





</body>

</html>

 

 

Screenshot

 

PHP Program

Save the changes and copy the file to Apache htdocs. You can also link the server in Eclipse. You can copy the file under a directory called first program. So that you can access the file with below URL.

http://localhost/firstprogram/AddNumbers.php

Start the Apache server and access the url from the browser as shown below.

 

PHP Program

Run the Program

Run the program. Enter sample values for a and b.

PHP Program

 

Click on the button. The result of the sum would be displayed.

 

 

—

PHP Tutorials

PHP Tutorials on this website:

https://www.testingdocs.com/php-tutorials/

More Information on PHP

https://www.php.net/

Related Posts

Compoer Command line command

PHP /

Install Slim Framework on Windows

php download website

PHP /

Download and Install PHP on Windows

Composer Install Windows

PHP /

Composer Download on Windows

Apache conf file

PHP /

PHP 7 Configuration in Apache Server

testing php linux

PHP /

Testing PHP with Apache Server on Linux

› Getting Started with PHP

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version