Parse error: syntax error, unexpected $end 解决方法
今天在Linux上调试PHP程序,后台数据库用的是MySQL,出现如下错误:
Parse error: syntax error, unexpected $endin/path/the.phponline24
检查了几次程序,都感觉没有什么错误。
最后,实在没办法了,就一行一行的逐行检查,终于发现了问题所在:
$sql = "INSE RT INTO treemenu VALUES( '$i', '$ip_addr', '3','2');
以上语句少了一个双引号,晕啊!
正确语句如下:
$sql = "INSERT INTO treemenu VALUES( '$i', '$ip_addr', '3','2')";
故障排除。
后来在网上一查,一般缺少 标点 就出现上述情况,看来以后写程序要多留意才行啊!
NOTE:我的情况是大括号没有配对出现,少了右大括号。而且文件有342行,一直提示是343行错误!
附:原文
InPHP 5, the following error may appears as an error entry in Apacheerror log or simply displays on PHP web page, even if calling tophp scripts with php_info() works perfectly and successfullyreturns information on PHP configurations:
Parse Error: syntax error, unexpected $end in ….. scripts.php online …
The error may caused by a missing curly bracket in PHP scriptcoding. Beside, it may also caused by error in PHP coding in classdefinition, as in PHP, a class definition cannot be broke up anddistributed into multiple files, or into multiple PHP blocks,unless the break is within a method declaration.
But more commonly, the error is often caused by the use of ShortOpen tags in PHP,
To use short open tags, it must be enabled in PHP.INI. Search forshort_open_tag in PHP.INI, and change the value to On. The lineshould look line:
short_open_tag = On