我正在努力让一个旧剧本恢复生机,但我不是最好的PHP,但练习使得完美。
有人可以解释或指出导致此错误的原因是我在下面。
解析错误:语法错误,意外''''(T_CONSTANT_ENCAPSED_STRING),期望第16行的C:\ xampp \ htdocs \ install \ step2check.php中的标识符(T_STRING)
// Check connection
if (mysqli_connect_errno())
{
echo "<br><br><br><br><center>
<h1><font color='red'>Failed to connect to MySQL</font></h1>
<h2>Please go back and check your MySQL Connection infomation</h2>
</center>
<a href='index.php' class='Start'>Back to Start</a>";
}
else {
#########################
## POPULATE connect.php##
#########################
file_put_contents("../connect.php", "");
$filename = '../connect.php';
$somecontent = '<?php
$db_host = \''.$POSThost.'\';
$db_user = \''.$POSTuser.'\';
$db_pass = \''.$POSTpass.'\';
$db_database = \''.$POSTdatabase.'\';
$link = @mysql_connect($db_host,$db_user,$db_pass) or die(\'Unable to establish a DB connection\');
mysql_query("SET NAMES \'utf8\'");
mysql_select_db($db_database,$link);
?>';
我希望有人可以提供帮助。
答案 0 :(得分:0)
//为什么设置为php变量来保存从其他PHP变量定义的其他php变量?无需复杂化,同时造成额外错误。试试这个:
// Check connection
if (mysqli_connect_errno())
{
echo "<br><br><br><br><center>
<h1><font color='red'>Failed to connect to MySQL</font></h1>
<h2>Please go back and check your MySQL Connection infomation</h2>
</center>
<a href='index.php' class='Start'>Back to Start</a>";
}
else {
#########################
## POPULATE connect.php##
#########################
file_put_contents("../connect.php", "");
$filename = '../connect.php';
$db_host = $POSThost;
$db_user = $POSTuser;
$db_pass = $POSTpass;
$db_database = $POSTdatabase;
$link = mysql_connect($db_host,$db_user,$db_pass) or die(\'Unable to establish a DB connection\');
mysql_query("SET NAMES \'utf8\'");
mysql_select_db($db_database,$link);
}
?>