简体   繁体   English

将数据从HTML表单传递到PHP文件

[英]Passing data from an HTML form to PHP file

Any help understanding why the below does not work would be a big help. 任何有助于理解以下内容为何不起作用的帮助都会有很大帮助。 I don't understand why $var1 does not get the contents of bnum in the PHP file. 我不明白为什么$ var1不能在PHP文件中获取bnum的内容。

Thank Marc 感谢Marc

HTML form in file#1 文件#1中的HTML表单

<html>
<body>

<form action="delete.php" method="post">
Please input building number to delete: <input type="text" name="bnum"><br>
<input type="submit">
</form>

</body>
</html>

Delete.php file Delete.php文件

<?php
echo $_POST["bnum"];
echo "<br>"; 

$var1 = $_post["bnum"];
echo "var1 = ";
echo $var1;
echo "<br>";

var_dump($_POST);
?>

Output 输出量

test
var1 = 
array(1) { ["bnum"]=> string(4) "test" }

$ _post与$ _POST不同...

$var1 = $_POST["bnum"];

Your code works fine! 您的代码工作正常!

You entered "test" into the text field. 您在文本字段中输入了“测试”。 You echoed the posted text and you got line 1 of the output "test". 您回显了所发布的文本,并且得到了输出“ test”的第1行。 You echoed "Var =" string and you got "var =". 您回显了“ Var =”字符串,并且得到了“ var =”。 You requested string information and line 3 told you that it is 4 characters and it is "test". 您请求了字符串信息,第3行告诉您它是4个字符,它是“测试”。

This script would need to connect to a database to actually do something meaningful. 该脚本需要连接到数据库才能实际执行有意义的操作。 What are you trying to accomplish? 你想达到什么目的?

$ _post的大字母..像这样$ _POST ['bnum']

$_POST like $_GET , $_REQUEST , $_COOKIE and $_SESSION ( amongst others ), are known as "Superglobals" and must be in uppercase letters, no exception. $_POST$_GET$_REQUEST$_COOKIE$_SESSION (其中包括 ),被称为“超级全局” ,并且必须是大写字母, 也不例外。

<?php
echo $_POST["bnum"];
echo "<br>"; 

$var1 = $_post["bnum"]; // INVALID $_post must be in uppercase
echo "var1 = ";
echo $var1;
echo "<br>";

var_dump($_POST);
?>

Valid: 有效:

<?php
echo $_POST["bnum"];
echo "<br>"; 

$var1 = $_POST["bnum"]; // VALID
echo "var1 = ";
echo $var1;
echo "<br>";

var_dump($_POST);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM