dopii22884 2017-02-15 11:38
浏览 404
已采纳

致命错误:未捕获PDOException:SQLSTATE [42000]

I get this error message, any help would be appreciated.

( ! ) Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 in index.php on line 96

( ! ) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 in index.php on line 96

This is the code:

$centroId = $_SESSION['userId'];
$orderby= 'id DESC';
if (isset($_GET['orderby'])){
    $orderby=filter_var($_GET['orderby'],FILTER_SANITIZE_STRING);
}
$where='';
$search='';
if (isset($_GET['cerca'])){
    $search=filter_var($_GET['cerca'],FILTER_SANITIZE_STRING);
    $where=' AND (cognome like "%'.$search.'%" OR nome like "%'.$search.'%" OR id='.$search.') ';
}
$perpage=3; 
$sql='SELECT count(id) FROM utenti2 WHERE centroId=:centroId AND legge_privacy="SI"  '.$where.'';
$result=$db->prepare($sql);
$result=$db->prepare($sql);
$result->bindParam(':centroId', $centroId, PDO::PARAM_INT);
$result->execute();  //line 96
  • 写回答

1条回答 默认 最新

  • douzhen1234 2017-02-15 11:51
    关注

    Try adding quotes around id=$search

    $where=' AND (cognome like "%'.$search.'%" OR nome like "%'.$search.'%" OR id="'.$search.'") ';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python使用pulp线性优化时报错
  • ¥15 开源或低价数据中台哪个最好
  • ¥15 arduino编程出现字符串疑似覆盖现象
  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?
  • ¥30 STK matlab python仿真
  • ¥15 关于IMageEnView 图标定位问题
  • ¥20 求解答(matlab)
  • ¥30 ffmpeg库使用过程中遇到的问题
  • ¥15 pyqt5 中python如何通过Qtwebchannel主动发消息给web前端
  • ¥15 关于HTML中title获取xml内容的问题