2017-02-15 9 views
0

Ich bekomme diese Fehlermeldung, jede Hilfe wäre willkommen.Schwerwiegender Fehler: Nicht abgefangene PDOException: SQLSTATE [42000]

(!) 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

Dies ist der 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

print_f Ihre SQL-Abfrage _ $ SQL_, wie sieht es aus? –

+0

Sie sollten Platzhalter für alle Werte verwenden, nicht nur 'centroId'. 'FILTER_SANITIZE_STRING' macht nichts, wenn es um die SQL-Injektion geht. – jeroen

Antwort

0

Versuchen Hinzufügen Anführungszeichen id=$search

$where=' AND (cognome like "%'.$search.'%" OR nome like "%'.$search.'%" OR id="'.$search.'") '; 
+0

danke das hat es gelöst! – Fetz

+0

Ich bin froh, dass ich helfen konnte. Bitte akzeptiere meine Antwort dann;) Prost – Cashbee

Verwandte Themen