PHP致命错误:未捕获异常';PDO异常';带有消息';SQLSTATE[42000]:
抱歉,我在我的错误日志中收到此错误PHP致命错误:未捕获异常';PDO异常';带有消息';SQLSTATE[42000]:,php,mysql,sql,Php,Mysql,Sql,抱歉,我在我的错误日志中收到此错误 PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1' in /home/payassur/public_html/admin/index.php:13
Stack trace:
#0 /home/payassur/public_html/admin/index.php(13): PDO->query('SELECT * FROM u...')
#1 {main}
thrown in /home/payassur/public_html/admin/index.php on line 13
下面是第13行
$query = $db->query("SELECT * FROM users WHERE id = $u_id");
您的查询是开放的,人们已经发现了这一点,因此正在尝试注入数据库。这就是为什么您的错误日志中会出现这些错误。您应该开始使用来防止SQL注入
if (isset($u_id) && trim($u_id) != '') {
$stmt = $db->prepare('SELECT * FROM users WHERE id = :u_id');
$stmt->exectue(array('u_id' => $u_id,));
$result = $stmt->fetchAll();
}else{
$results = [];
}
了解防止SQL注入的准备语句看起来$u_id为空。请检查我已经检查过了。用户idSo
$u\u id
是否有值?如果您回显查询,它看起来如何?不,$u\u id没有值,只有id。如果$\u id像opid一样为空,那么这没有帮助,为什么它应该为空?有人可能已将查询字符串更改为www.example.com?u\u id='
。OP表示他/她在错误日志中发现了此错误,因此确定这不是因为OP仍在测试他/她自己的代码吗?请参阅OP的注释:否,$u_id没有值。OP表示,$u_id
持有的是一个id,不是一个值,$u_id没有值,但id
,这不会使其为空