By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Sum two (2) numbers in PHP with HTML input form

+4 votes
  1. Write a PHP script to sum two numbers.
  2. The script should display HTML form to enter the numbers.
  3. If the numbers are passed as parameters, display their sum.
asked in PHP category by user john7

1 Answer

+3 votes
Best answer

Here's my solution:

<!DOCTYPE html>

    <div>Number 1:</div>
    <input type="number" name="num1"/>
    <div>Number 2:</div>
    <input type="number" name="num2"/>
    <div><br><input type="submit" value="CHECK THE SUM"></div><br>

if (isset($_GET['num1']) && isset($_GET['num2'])) {

    $num1 = $_GET['num1'];
    $num2 = $_GET['num2'];
    $sum = $num1 + $num2;
    echo $num1 . " + " . $num2 . " = " . $sum;



answered by user Jolie Ann
selected by user golearnweb