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

致命错误:未捕获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 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波