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

时间:2019-04-19 18:26:47

标签: php html 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>

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

24

3 个答案:

答案 0 :(得分:0)

您可以使用dlogsocket.onmessage = function (event) { $("#ws-dlog-data").append(event.data); // If more than 100 spans, remove the first (oldest). if( $("#ws-dlog-data span").length >100 ){ $("#ws-dlog-data span").first().remove(); } }; 来获得$_GET$_POST请求

$_REQUEST

答案 1 :(得分:0)

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

答案 2 :(得分:0)

最好检查输入以避免可能的错误。您可以尝试以下示例:

<?php
if( $_POST["length"] && $_POST["numPass"] ) { 
    echo "1: " . $_POST['length'] . "<br>";
    echo "2: " . $_POST['numPass'] . "<br>";
    echo $_POST['length'] * $_POST['numPass'];
}
?>

<form method="post" action = "<?php $_PHP_SELF ?>">
    <input type="number" name="length">
    <input type="number" name="numPass">
    <input type="submit">
</form>