duanchoupo1104 2015-11-05 01:51
浏览 30

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

This is my first php program. Im trying to compare the result of adding two randomly generated numbers (visually displayed before text field) to the answer i give in the submit. But it just wont work. I pass the result at $value3 and try to compare it to the result of the submit. Any ideas guys?

<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条回答 默认 最新

  • dongmei6426 2015-11-05 02:11
    关注

    Try this

    <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?