通过POST / GET发送的值将不会打印为变量

我正在一个项目中,将两个提交的变量转换为php变量(最终它们将相乘),但截至目前,我无法将变量视为此类/回声。


我尝试从POST更改为GET,并且变量通过发送(出现在查询行中),但它们不打印在页面上


<?php

    if (isset($_POST['submit'])) {

        echo $_POST['length'];


        echo $_POST['numPass'];

    }

?>


<form method="post" action="">

    <input type="number" name="length">

    <input type="number" name="numPass">

    <input type="submit">

</form>

我希望变量将作为常规语句回显。IE。长度= 2和numPass = 4


24


温温酱
浏览 151回答 3
3回答

LEATH

您可以使用$_GET并$_POST请求$_REQUESTif (isset($_REQUEST['submit'])) {&nbsp; &nbsp; echo $_REQUEST['length'];&nbsp; &nbsp; echo $_REQUEST['numPass'];}<form method="post" action="">&nbsp; <input type="number" name="length">&nbsp; <input type="number" name="numPass">&nbsp; <input type="submit" value="submit"></form>

一只萌萌小番薯

$ POST ['submit']不存在,因为您的提交按钮没有名称,它需要的名称与其他输入的名称相同

尚方宝剑之说

最好检查输入以避免可能的错误。您可以尝试以下示例:<?phpif( $_POST["length"] && $_POST["numPass"] ) {&nbsp;&nbsp; &nbsp; echo "1: " . $_POST['length'] . "<br>";&nbsp; &nbsp; echo "2: " . $_POST['numPass'] . "<br>";&nbsp; &nbsp; echo $_POST['length'] * $_POST['numPass'];}?><form method="post" action = "<?php $_PHP_SELF ?>">&nbsp; &nbsp; <input type="number" name="length">&nbsp; &nbsp; <input type="number" name="numPass">&nbsp; &nbsp; <input type="submit"></form>
打开App,查看更多内容
随时随地看视频慕课网APP