我试图获得有关DB中已保存行的确认,但我的条件总是返回FALSE。
$conn = new PDO($dir) or die("hovno");
$query = "INSERT INTO sncheck (caseId, snPaper, snBox, snUnit) VALUES ('$caseId', '$snPaper', '$snBox', '$snUnit')";
$prep = $conn->prepare($query);
if($prep->execute()){
print "DONE";
}
else{
print "ERROR";
}
它始终触发else
语句。
答案 0 :(得分:1)
更改为:
$req = $conn->prepare("INSERT sncheck users (caseId, snPaper, snBox, insnUnitos, roles_id) VALUES (:login, :password, :email, :infos, :snUnit)")or exit(print_r($conn->errorInfo()));
$req->execute(array(
"caseId" => $caseId,
"snPaper" => $snPaper,
"snBox" => $snBox,
"nUnit" => $nUnit
));
答案 1 :(得分:0)
尝试调试您的查询,如下所示,这样您就会收到正确的错误消息 -
$conn = new PDO($dir) or die("hovno");
$query = "INSERT INTO sncheck (caseId, snPaper, snBox, snUnit) VALUES ('$caseId', '$snPaper', '$snBox', '$snUnit')";
$prep = $conn->prepare($query);
if (!$prep) {
echo "\nPDO::errorInfo():\n";
print_r($conn->errorInfo());
}
if($prep->execute()){
print "DONE";
}else{
echo "\nPDO::errorInfo():\n";
print_r($conn->errorInfo());
print "ERROR";
}
如果仍有问题,请告诉我,并提供错误消息。