我想将一些变量写入文件以将它们包含在另一个脚本中。但是我在运行脚本时遇到了这些错误:
Notice: Undefined variable: host in I:\xampp\htdocs\contact\install\writeconfig.php on line 2
Notice: Undefined variable: database in I:\xampp\htdocs\contact\install\writeconfig.php on line 2
Notice: Undefined variable: user in I:\xampp\htdocs\contact\install\writeconfig.php on line 2
Notice: Undefined variable: password in I:\xampp\htdocs\contact\install\writeconfig.php on line 2
HTML 表单:
<html>
<head>
<title>Contact installatie</title>
</head>
<body>
<h1>Contact installatie</h1>
<h2>Database gegevens:</h2>
<form name="databasesettings" action="writeconfig.php" method="post">
Host: <input type="text" name="host"> <br>
Database: <input type="text" name="database"> <br>
User: <input type="text" name="user"> <br>
Password: <input type="password" name="password"> <br>
<input type="submit" value="Generate config">
</form>
</body>
</html>
和PHP代码:
<?php
$config = "$host = " . $_POST["host"] . "\n$database = " . $_POST["database"] . "\n$user = " . $_POST["user"] . "\n$password = " . $_POST["password"];
$configfile=fopen("config.txt","w+");
fwrite($configfile, $config);
fclose($configfile);
?>