Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 结合isset和elseif语句_Php_Html - Fatal编程技术网

Php 结合isset和elseif语句

Php 结合isset和elseif语句,php,html,Php,Html,我想问一下这个代码是否可行?我想发生的是,它只会在按下submit后发出回声 <!DOCTYPE html> <html> <body> <?php $x = $_POST['x']; $y = $_POST['y']; $z = $x + $y; if (isset($_POST['submit'])) { if($z < "10") { echo "Higher!"; } elseif ($z > "1

我想问一下这个代码是否可行?我想发生的是,它只会在按下submit后发出回声

<!DOCTYPE html>
<html>
<body>

<?php
$x = $_POST['x'];
$y = $_POST['y'];
$z = $x + $y;

if (isset($_POST['submit'])) {
    if($z < "10") {
        echo "Higher!";
    } elseif ($z > "10"){
        echo "Lower!";
    } else {
        echo "You're right!";
    }
}
?>

<form action="index.php" method="post">
<input type="number" name="x">
&nbsp;+&nbsp;
<input type="number" name="y">
<input type="submit" value="EQUALS">
</form>

</body>
</html>

您必须将某些字段命名为“submit”,因为在if语句中,您正在检查是否设置了名为submit的字段。在HTML中没有这样的字段。您可以使用提交按钮。您必须做的唯一一件事就是将值为submit的属性name放在submit按钮中

<!DOCTYPE html>
<html>
    <body>
        <?php

        if (isset($_POST['submit'])) {
            $x = $_POST['x'];
            $y = $_POST['y'];
            $z = $x + $y;

            if($z < 10) {
                echo "Higher!";
            } elseif ($z > 10){
                echo "Lower!";
            } else {
                echo "You're right!";
            }
        }
        ?>

        <form action="" method="post">
            <input type="number" name="x">
            &nbsp;+&nbsp;
            <input type="number" name="y">
            <input type="submit" name="submit" value="EQUALS">
        </form>
    </body>
</html>


感谢您的快速回复@Velko Georgiev。它起作用了。我刚刚接触PHP和MySQL的世界,并在W3学校读书。