创建安装程序脚本
我正在尝试使用 fwrite 和表单的组合来创建一个安装程序。这是我的代码:
<?php
$myFile = "db_config.php";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "$host = " . $_POST['host'] . ";\n $username = " . $_POST['username'] . ";\n $password = " . $_POST['password'] . ";\n $name = " . $_POST['name']";" ;);
fwrite($fh, 'mysql_connect("{$host}", "{$db_username}", "{$db_password}")\n or die(mysql_error());\n mysql_select_db("{$db_name}")\n or die(mysql_error()); ?>' ;);
fclose($fh);
?>
这是错误:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home2/runetyco/public_html/ballpointradio/new/install_action.php on line 4
I'm trying to create an installer, using a combination of fwrite and forms. Here's my code:
<?php
$myFile = "db_config.php";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "$host = " . $_POST['host'] . ";\n $username = " . $_POST['username'] . ";\n $password = " . $_POST['password'] . ";\n $name = " . $_POST['name']";" ;);
fwrite($fh, 'mysql_connect("{$host}", "{$db_username}", "{$db_password}")\n or die(mysql_error());\n mysql_select_db("{$db_name}")\n or die(mysql_error()); ?>' ;);
fclose($fh);
?>
Here's the error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home2/runetyco/public_html/ballpointradio/new/install_action.php on line 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您在行尾缺少
.
You are missing a
.
at the end of the line相当多的问题 tbh.. 排序
注意:我不建议这样做,通常最好只写出一个简单的配置文件并保持所有代码静态,但上面回答了您关于所得到的错误的问题。
quite a few problems tbh.. sorted
note: i wouldn't recommend doing it this way, typically much better to only write out a simple config file and keep all code static, but the above answers your question about the error you get.
问题可能出在
?>
中。你必须逃避它。另外,您没有将放在 conf 文件的开头。
为什么你想要它是 php 文件呢?为什么不使用 ini 文件和 parse_ini_file() 或 xml或许?
problem might be in
?>
. you'll have to escape it. also, you are not putting<?php
in the beginning of your conf file.why do you want it to be php file anyway. why not use ini file and parse_ini_file(), or xml maybe?
它给出错误的原因是因为它正在第 4 行查找变量 $host - 如果将双引号更改为单引号,它应该可以解决问题 - 见下文:
The reason it's giving an error is because it's looking for the variable $host on line 4 - if you change the double quotes to single it should fix the problem - see below: