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

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com