我在 $_POST 变量上收到未定义的索引错误。 IE。 $_POST['主机名'].我知道为什么我会得到它们,但是有没有办法将 php 和表单保存在同一个文件中并且不会出现这些错误?
<html>
<head>
<title>Install Forum</title>
</head>
<body>
<h1>Please enter your database information</h1>
<form action='install.php' method='post'>
Hostname: <input type='text' name='hostname'><br/>
MySQL User: <input type='text' name='dbuser'><br/>
MySQL Pass: <input type='password' name='dbpassword'><br/>
<input type='submit' name='submit' value='Submit'><br/>
</body>
</html>
<?php
include_once("config.php");
$date = date('Y-m-d');
//Database Variables
$dbhost = strip_tags($_POST['hostname']);
$dbuser = strip_tags($_POST['dbuser']);
$dbpass = strip_tags($_POST['dbpassword']);
$submit = isset($_POST['submit']);
将您的 PHP 代码包装在if
与isset
健康)状况。这样,只有在提交表单后才会运行代码:
if(isset($_POST['submit']))
{
include_once("config.php");
$date = date('Y-m-d');
//Database Variables
$dbhost = strip_tags($_POST['hostname']);
$dbuser = strip_tags($_POST['dbuser']);
$dbpass = strip_tags($_POST['dbpassword']);
$submit = isset($_POST['submit']);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)