basic calculator program in php

technical talkiess
0

 <!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Php calculator</title>
</head>

<?php
$result = '';
if(isset($_POST['operator'])){
    $fnumber = $_POST['first_num'];
    $snumber = $_POST['second_num'];
    $op_value = $_POST['Btn'];

    switch($op_value){
        case 'Add';
        $result = $fnumber + $snumber;
        break;
        case 'Subtract';
        $result = $fnumber - $snumber;
        break;
        case 'Multiply';
        $result = $fnumber * $snumber;
        break;
        case 'Divide';
        $result = $fnumber / $snumber;
        break;
        default:
        $result = 'Null';
        break
    }

}

?>

<body>
    <div id="page-wrap">
    <h1>PHP - Simple Calculator Program</h1>
      <form action="" method="post" id="quiz-form">
            <p>
                <input type="number" name="fnumber" id="fnumber" required="required" value="<?php echo $fnumber; ?>" /> <b>First Number</b>
            </p>
            <p>
                <input type="number" name="snumber" id="snumber" required="required" value="<?php echo $snumber; ?>" /> <b>Second Number</b>
            </p>
            <p>
                <input readonly="readonly" name="result" value="<?php echo $result; ?>"> <b>Result</b>
            </p>
            <input type="submit" name="Btn" value="Add" />
            <input type="submit" name="Btn" value="Subtract" />
            <input type="submit" name="Btn" value="Multiply" />
            <input type="submit" name="Btn" value="Divide" />
      </form>
    </div>
</body>
</html>



Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)