我想寫一些變量到一個文件,以便將它們包含在另一個腳本中。但我運行腳本,而得到這些錯誤:
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);
?>
逃避它們。在字符串中的'$'之前使用'\'。 – Rocky
嘿,看,答案!但是,它被張貼爲回覆?這麼奇怪? _Hope你得到的point._ – Sydcul
沒關係有關'\ N'的事情,這是因爲我在Windows(我的開發PC)上運行。如果你有這樣的問題太多,你應該使用'\ r \ N' – Sydcul