Write a simple calculator in php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Calculator</title>
</head>
<body>
<form  method="post">
    <table  align="center">
        <tr>
            <td  align="center">第一个数</td><td><input type="text" name="first"></td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="radio" name="operator" value="+">+
                <input type="radio" name="operator" value="-">-
                <input type="radio" name="operator" value="*">*
                <input type="radio" name="operator" value="/">/
            </td>
        </tr>
        <tr>
            <td  align="center">第二个数</td><td><input type="text" name="second"></td>
        </tr>
        <tr>
            <td> <input type="submit" value="提交"></td>
        </tr>
    </table>
</form>
<?php
header("content-type:text/html;charset=utf-8");
    $first=$_POST['first'];
    $second=$_POST['second'];
    $operator=$_POST['operator'];
    echo 'The result is:';
    if ( $operator == '+' )
    {
        echo $first+$second;
    }
    if($operator == '-')
    {
        echo $first-$second;
    }
    if($operator == '*')
    {
        echo $first*$second;
    }if($operator == '/')
    {
        echo $first/$second;
    }
    ?>
</body>
</html>

 This will report a warning:

I checked on the Internet and reported this warning because I received a null value.

So this thing can be ignored.

Solution:

https://www.baidu.com/link?url=gy5XGLhoRy8bUMPZLMcTGuWl7nQKAXt9Zrn642HRBhAcZS5oRax1KFrga5IqAxzXlKs5Xv3qGnc68AjakEKIW_&wd=&eqid=bb0491f00000160a000000025ae170a7

operation result:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324888590&siteId=291194637