我试图不允许用户在同一天下订单。我的SQL和PHP不会从此代码返回错误。但是,它不会返回任何内容,甚至不会下订单。
任何帮助将不胜感激
//Check if the date has been taken
$sql = "SELECT * FROM orders WHERE date='$date'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 1) {
header("Location: ../placeorder.php?order=taken");
exit();
} else {
header("Location: ../placeorder.php");
exit();
}
}
//Insert orders into database
$sql = "INSERT INTO orders (user_id, price, time, date, type, square_ft, materials ) VALUES ('$userid','$price', '$time', '$date', '$type', '$square_ft','$materials' );";
mysqli_query($conn, $sql);
header("Location: ../placeorder.php?=order=success");
exit();
我所要做的就是在$ resultCheck之后删除else语句。加集($ resultCheck> 0)。
//Check if the date has been taken
$sql = "SELECT * FROM orders WHERE date='$date'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
header("Location: ../placeorder.php?order=taken");
exit();
}
}
//Insert orders into database
$sql = "INSERT INTO orders (user_id, price, time, date, type, square_ft, materials ) VALUES ('$userid','$price', '$time', '$date', '$type', '$square_ft','$materials' );";
mysqli_query($conn, $sql);
header("Location: ../placeorder.php?=order=success");
exit();
}