PHP常见错误主要分为3块:
1、语法错误
Parse error: syntax error, unexpected T_VARIABLE in E:\guestbook\user.php on line 268
一般是少分号,在上一行或者下一行都有可能
Parse error: syntax error, unexpected '.' in F:\www\blog\article.php on line 100
多个“.”,类似的还有多个“;”等等
Notice: Undefined variable: a in ...
使用了一个没有被定义的变量a
Parse error: syntax error, unexpected T_ELSE in
if else if else 句式逻辑错误
Parse error: syntax error, unexpected $end in
一般是大括号不匹配
Parse error: syntax error, unexpected T_STRING in
一般是忘了写句末分号
Warning: Invalid argument supplied for foreach() in
foreach 的第一个参数必须是一个数组
Warning: Wrong parameter count fora in
函数参数个数不对
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\www\blog\index.php:10) in F:\www\blog\includes\config.inc.php on line 10
Warning: annot modify header information - headers already sent by (output started at F:\www\blog\index.php:10) in F:\www\blog\includes\config.inc.php on line 12
session前面不能有输出,同意的cookie也是这样的
Fatal error: Cannot redeclare
函数已经定义过,不能重新再定义;类也不能同名
2、SQL语句错误
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
说明前面执行SQL 返回失败,一般可能是SQL语句错误 ,如分析不出来,可以Mysql_error () 看具体是哪个地方错了
No database selected
一般是没有连接数据库
Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘root’@'localhost’ (using password: YES) in ….. on line 3Access denied for user ‘root’@'localhost’ (using password: YES)
数据库用户名的密码错误
Unknown database ‘cms07261′
数据库不存在
Table ‘cms0726.test’ doesn’t exist
表不存在
Unknown column ‘abc’ in ‘field list’
字段不存在
Column count doesn’t match value count at row 1
sql语句中 字段值的个数比字段名个数不一样
3、模板错误
Fatal error: Smarty error: [in message_list.html line 22]: syntax error: ‘foreach: item’ must be a variable name (literal string)
foreach 后面的item 后面必须跟一个变量名,不加$,是一个字符串
Fatal error: Smarty error: [in admin/tpl/class_detail.html line 14]: syntax error: unrecognized tag: cs.student_id (Smarty_Compiler.class.php, line 436) in D:\www\web\xmphp\inc\smarty\Smarty.class.php on line 1088
smarty语法错误:循环数组的时候,少$
Warning: Smarty error: unable to read resource: “message_list1.html” in
模板文件找不到,看是否是文件名写错或文件存放到别的目录中去了。
Fatal error: Smarty error: [in order_detail.html line 171]: syntax error: unclosed tag \{elseif} (opened line 157). (Smarty_Compiler.class.php, line 317) in F:\www\guestbook\xmphp\inc\smarty\Smarty.class.php on line 1088
html页面语法错误,少结束标签<%/if%>