【发布时间】:2019-07-06 16:23:37
【问题描述】:
不知道为什么会报错
致命错误:未捕获的 PDOException:SQLSTATE[42000]:语法错误或 访问冲突:1064 您的 SQL 语法有错误;检查 与您的 MySQL 服务器版本相对应的手册 在第 1 行的“预处理器”附近使用的语法 /var/www/html/phpquiz/result.php:17
执行准备好的语句时发生错误,即在执行时
$cho->execute();
<?php
session_start();
if(!isset($_SESSION['score'])){
$_SESSION['score'] = 0;
}
if(isset($_POST['submit'])){
$arr = array("a", "b", "c", "d", "e");
for($i = 1; $i < 6; $i++){
$text = $_POST['que_'.$arr[$i-1]];
echo "$text<br> ";
$cho = $pdo->prepare("SELECT id from choices where `text` = $text");
$cho->execute();
$r = $cho->fetch(PDO::FETCH_ASSOC);
echo $r;
}
}
【问题讨论】:
-
你没有正确使用prepare,
= $text"应该是= ?"然后execute([$text])