php - 如何解决:值未分配给 PHP 中的变量
问题描述
HTML 表单有一个输入字段。用户将在 HTML 表单中输入值,并根据该值采取进一步的步骤。
输入字段接受字符,这就是正在输入的内容。在 HTML 表单中,它被正确定义。
问题是输入的值没有存储在 PHP 的变量中。这真的很简单,但由于某种原因,我无法发现问题。
请注意,这不是将要部署的实际代码。我正在处理已部署代码中的 SQL 注入。只需要弄清楚这里出了什么问题。
我尝试显示表单中输入的值。它只返回 NULL。我在这里做错了什么?
<?php
$host = 'localhost';
$dbname = 'dbname';
$username = 'user';
$password = 'password';
$mysqli = new mysqli("localhost", "user", "password", "dbname");
if($mysqli->connect_error)
{
die("$mysqli->connect_errno: $mysqli->connect_error");
}
$field1=$_POST['field1'];
var_dump($field1);
?>
HTML 代码:
<!DOCTYPE html>
<html>
<body>
<basefont face = "sans-serif" size = "2" color = "#ff0000">
<form id="queryForm" method="POST" action="/test.php">
<div class="row">
<fieldset class="hm-fieldset">
<legend class="hm-legend">Enter Query Criteria:</legend>
<div class="col">
<span style="font-family:sans-serif">
Field1<br> <input type="text" id="field1" style="height:10px;
width:105px"> </span>
</div>
<button>Submit</button>
</fieldset>
</div>
</form>
</body>
</html>
解决方案
推荐阅读
- mysql - Node.js Sequelize virtual column pulling value from other model
- r - 选择文件小部件:“FUN 中的错误:找不到对象‘类型’”
- git - How to know the branch name of a commit
- angular - How can I execute ng test for all components of sub modul of Angular app
- c# - 如何在 AspNet Core 中实现 Front-Controller 设计模式?
- nginx - 使用 nginx 在 GCP VM 上设置 Google 域。?
- java - 检测应用程序语言而不是电话语言
- windows - Windows cannot run .ksh script
- django - Django: Pagination ListView and return json
- visual-c++ - 在 C++ 中创建单链表有点麻烦