我一直在使用准备好的语句在PHP中构建代码验证系统。该系统可以正常工作,就像我可以输入正确的代码一样,它会将我定向到正确的位置,但是,当我输入错误的代码时,它会将我带到PHP文件,而应该将我带到特定的URL。因此,我认为包含!mysqli_stmt_prepare的if语句是错误的,因为它根本无法运行。
<?php
if (isset($_POST['code-submit'])) {
require 'notseendatabasehandler.php';
$code = $_POST['code'];
//Checking for empty fields
if (empty($code)) {
header("Location: codeinput.php?error=emptyfields");
exit();
}
$sql = "SELECT codeNumber
FROM verificationcodes
WHERE codeNumber=?;";
$stmt = mysqli_stmt_init($conn);
// If the user enters an incorrect code
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: codeinput.php?code=notmatching");
exit();
} else {
//If the user enters a correct code
mysqli_stmt_bind_param($stmt, "s", $code);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
header("Location: testpage2.php?code=success");
exit();
}
}
} else {
//Sending the user backwards if they entered incorrectly
header("Location: homepage.php");
exit();
}
解决方案可能非常简单,但是任何帮助将不胜感激!谢谢!