Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Sum two numbers in PHP with HTML input form

<!DOCTYPE html>
<html>
<head>
    <title>Sum</title>
</head>
<style>
    body {
        background: linear-gradient(110deg, #fdcd3b 60%, #ffed4b 60%); 
    }
    .container {
        width: 400px;
        margin: 0 auto;
        background-color: #eee;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0px 0px 10px #000;
    }
    .container1{
        width: 100px;
        margin: 0 auto;
        background-color: #eee;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0px 0px 10px #000;
        text-align: center; 
    }
    .container input {
        width: 80%;
        padding: 10px;
        margin-bottom: 10px;
    }
    .container button {
        width: 80%;
        padding: 10px;
        margin-bottom: 10px;
    }
    .container .result {
        width: 100%;
        padding: 10px;
        margin-bottom: 10px;
    }
     form{
            width: 300px;
            margin: 0 auto;
            text-align: center;
     }
        input{
                width: 200px;
                height: 30px;
                margin: 10px;
                border: 1px solid #ccc;
                border-radius: 5px;
                padding: 5px;
        }
        .container{
            width: 300px;
            margin: 0 auto;
            text-align: center;
            background-color: #ccc;
        }
        button{
            margin: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 5px;
            background-color: #34568B;
            width: 200px;
            color: #fff;
            font-weight: bold;
            font-size: 20px;
            padding: 10px;
            width: 200px;
        }
        button:hover{
            margin: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #FF6F61;
            width: 200px;
            color: #fff;
            font-weight: bold;
            font-size: 20px;
            padding: 5px;
            width: 200px;
        }
 </style>
<body>
<div class="container">
<form>
    <input type="number" name="num1" placeholder="Number 1" />
    <input type="number" name="num2" placeholder="Number 2" />
    <button input type="submit" value="CHECK THE SUM">submit</button>
</form>
</div>

<?php
if (isset($_GET['num1']) && isset($_GET['num2'])) {
 
    $num1 = $_GET['num1'];
    $num2 = $_GET['num2'];
    $sum = $num1 + $num2;
    echo "<div class='container1'>";
    echo "<div class='result'>";
    echo  $num1 . " + " . $num2 . " = " . $sum;
}
?>
 
</body>
</html
Source by forum.tutorials7.com #
 
PREVIOUS NEXT
Tagged: #Sum #numbers #PHP #HTML #input #form
ADD COMMENT
Topic
Name
3+1 =