我有一个准备好的 php 语句来在我的数据库中插入一行。我在此过程中进行了(我认为的)错误检查。最后有一个错误检查$stmt->execute()。如果它返回,false我希望它取消INSERT操作并显示我的消息。值是false但INSERT仍然成功。我曾假设如果$stmt->execute()===false那时INSERT我的数据库中没有。
如果这是重复的,我深表歉意,我无法找到与我类似的先前问题。
这是导致问题的部分:
$sql = "INSERT INTO login (username, password, name, branch, officer, type, alerts) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $nbadmin->prepare($sql);
if(false===($nbadmin->prepare($sql))){
$nbadmin->close();
echo '<script>alert("Something went wrong; try again.")</script>';
error();
}
$stmt->bind_param('sssssss', $user, $pass, $name, $branch, $officer, $type, $alert);
if(false===($stmt->bind_param('sssssss', $user, $pass, $name, $branch, $officer, $type, $alert))){
$nbadmin->close();
echo '<script>alert("Something went wrong; try again.")</script>';
error();
}
$stmt->execute();
if(false===($stmt->execute())){
$nbadmin->close();
echo '<script>alert("Something went wrong; try again.")</script>';
error();
}else{
$nbadmin->close();
finish();
}
function error(){
header("Refresh: 0; url=../edit-user.php#user-form");
}
拉莫斯之舞