我正在做一个项目,接受两个提交的变量,并将它们转换为php变量(最终它们会相乘),但到目前为止,我还不能将变量视为这样的/echo。
我尝试从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>
我希望这些变量将作为常规语句得到响应。即。length=2和numPass=4
24
发布于 2019-04-20 02:38:23
您可以使用$_REQUEST
获取$_GET
和$_POST
请求
if (isset($_REQUEST['submit'])) {
echo $_REQUEST['length'];
echo $_REQUEST['numPass'];
}
<form method="post" action="">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit" value="submit">
</form>
发布于 2019-04-20 02:38:33
$POST“submit”不存在,因为“提交”按钮没有名称,它需要一个与其他输入相同的名称
发布于 2019-04-20 18:16:17
最好检查输入以避免可能的错误。你可以试试它的例子:
<?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>
https://stackoverflow.com/questions/55766183
复制相似问题