如何在表单提交后传递算术运算结果?

时间:2015-11-05 01:51:04

标签: php html

这是我的第一个php程序。我试图比较将两个随机生成的数字(在文本字段之前可视化显示)添加到我在提交中给出的答案的结果。但它不会工作。我将结果传递给$ value3并尝试将其与提交结果进行比较。任何想法的家伙?

<head>
    <title>
    </title>
</head>

<?php
    $displayForm=True;
    if(isset($_GET['result'])){     
        $displayForm=False;
    }
    if($displayForm){   
?>

<body>
    <form method="GET">
        result 
        <?php
            $value1=rand(1,10);
            $value2=rand(1,10);
            $value3=$value1 + $value2;
            echo($value1);
            echo("+");
            echo($value2);
        ?>
        <input type="text" name="number">
        <input type="hidden" name="val3" value="$value3">
        <input type="submit" name="result" value="submit">
    </form>

    <?php
       }
            if(isset($_GET['result'])){ 
            if(isset($_GET['result'])){ 
                $result = $_GET['result']; 
            } 
            if($result==$_GET['val3']){
                echo "result right: you re human";
            }
            else{
                echo "lol you are a retarded cat";
            }
        }
    ?>
</body>

1 个答案:

答案 0 :(得分:0)

试试这个

<body>
        <form method="GET">
            result 
            <?php
                $value1=rand(1,10);
                $value2=rand(1,10);
                $value3=$value1 + $value2;
                echo($value1);
                echo("+");
                echo($value2);
            ?>
            <input type="text" name="number">
            <input type="hidden" name="val3" value="<?php echo $value3; ?>">
            <input type="submit" name="result" value="submit">
        </form>

        <?php
           }
           if(isset($_GET['result'])){ 
                if(isset($_GET['result'])){ 
                    $result = $_GET['number']; 
                } 
                if($result==$_GET['val3']){
                    echo "result right: you re human";
                }
                else{
                    echo "lol you are a retarded cat";
                }
            }
        ?>
    </body>