I'm trying to delete a row from an SQL table where a row contains the user Id and the column bookingComplete is = to 'No'. However it doesn't seem to be deleting the row. Does anyone know why?
if (isset($_SESSION['userID'])) {
$user = $_SESSION['idUsers'];
$sql = "DELETE FROM userhousecleaninfo WHERE idUsers = $user AND bookingComplete = 'No'";
mysqli_query($conn, $sql);
setcookie($postcode_cookie_name, $postcode, time() + (40000), "/"); //Cookie available for about 10 hours
header('Location: booking.php');
exit();
}
Your Query seems fine to me but I see there is no logic in using And statement. Hope iduser attribute is Unique integer. Check the you idUsers attribute also in your table. Besides Sql is case insensitive . You can simply use DELETE FROM userhousecleaninfo WHERE idUsers = $user
.
Not sure is it a solution, but have a try:
$sql = "DELETE FROM userhousecleaninfo WHERE idUsers = '".$user."' AND bookingComplete = 'No'";
PS Is your "bookingComplete" in database set to varchar? If it's int - so probably doesn't storing your data into field and getting error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.