2017-09-30 11 views
-1

J'ai lu et essayé dur pendant les deux dernières heures pour exécuter mon code. Mais j'ai une erreur de syntaxe dans ma requête sql, quelqu'un peut-il m'aider?PDOException Uncaught: SQLSTATE [42000] - Essayez d'insérer des données

Mon code:

$query = "INSERT INTO `article` (`text`,`headline`,`date`,`author`,`active`) SET (?,?,?,?,?)"; 
$stmt = $pdo->prepare($query); 
$stmt->bindValue(1, $text, PDO::PARAM_STR); 
$stmt->bindValue(2, $headline, PDO::PARAM_STR); 
$stmt->bindValue(3, $date, PDO::PARAM_STR); 
$stmt->bindValue(4, $author, PDO::PARAM_STR); 
$stmt->bindValue(5, $active, PDO::PARAM_INT); 
if($stmt->execute()) { //do something } 

Erreur fatale:

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 'SET ('some text','test headline','2017-09-30','author123',1)'

BTW, comment puis-je utiliser php codes-tags?

Merci

Répondre

-1

Essayez de changer « SET » dans votre requête aux « valeurs », votre utilisation de « SET » est incorrect dans ce contexte.