Home  >  Q&A  >  body text

I saw a calculator written in PHP on the Internet, but it cannot achieve calculation output. Please help!

如题,源码如下

<!DOCTYPE html>

<html>

<head>

    简易计算器

</head>

<body>   

<?php

    $num1 = $_GET["num1"];

    $num2 = $_GET["num2"];

    if($_GET["ysf"]==" ")

        $sun = $num1 $num2;

    if($_GET["ysf"]=="-")

        $sun = $num1-$num2;

    if($_GET["ysf"]=="*")

        $sun = $num1*$num2;

    if($_GET["ysf"]=="/")

        $sun = $num1/$num2;

?>

<form action="" method="get">

        <input type="text" name="num1"></input>

        <select name="ysf">

            <option value=" "> </option>

            <option value="-">-</option>

            <option value="*">*</option>

            <option value="/">/</option>

        </select>

        <input type="text" name="num2"></input>

        <input type="submit" value="计算" name="sub" />

</form>

 

<?php

    if(isset($_GET["sub"]))

        echo $sun;

?>

 

</body>

</html>


季风季风2391 days ago1471

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2018-04-26 14:33:15

    There is no problem after reading the code. The final output is

    <?php
        if(isset($_GET["sub"]))
            echo $sun;
    ?>


    reply
    0
  • 无忌哥哥

    无忌哥哥2018-04-25 19:06:17

    Look at what the error is

    reply
    0
  • 季风

    No error was reported, but the final calculated result was not displayed. Did I miss something?

    季风 · 2018-04-26 14:38:23
  • Cancelreply