What am I doing wrong. The first 'if' statement deletes an entry (as expected). The first 'else if' statement adds an entry (as expected). But the final 'else if' statement (which is exactly the same code as the first if statement, except for the 'WHERE' clause being reduced) does not delete the entries from the database.
There is also no sqli_error. The output from this code (when $clear = TRUE) is:
Unable to execute CLEAR ALL query.
Error code :
Any help would be much appreciated.
Regards,
DLW
/********************** PROBLEM CODE **********************/
if (!empty($deleteFilm)) {
$sqlString = "DELETE FROM orders WHERE dvd = '$deleteFilm' and customer = '$usrName';";
if ($queryResult = @mysqli_query($connection, $sqlString)) {
$msg = "The item has been removed from your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
else {
$error = "<p>Unable to execute DELETE ORDER query."
. "<br />Error code " . mysqli_errno($connection)
. ":" . mysqli_error($connection)."</p>";
header("location: memberOrders.php?error=$error");
exit;
}
}
else if (!empty($addFilm)) {
$sqlString = "INSERT INTO orders VALUES ('$addFilm', '$usrName');";
if($queryResult = @mysqli_query($connection, $sqlString)) {
$msg = "The item has been added to your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
else {
$error = "<p>Unable to execute ADD FILM query."
. "<br />Error code " . mysqli_errno($connection)
. ":" . mysqli_error($connection)."</p>";
header("location: memberOrders.php?error=$error");
exit;
}
}
else if($clear) {
$sqlString = "DELETE FROM orders WHERE customer = '$usrName';";
if ($queryResult = @mysqli_query($connection, $sqlString)) {
$msg = "All items have been removed from your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
else {
$error = "<p>Unable to execute CLEAR ALL query."
. "<br />Error code " . mysqli_errno($connection)
. ":" . mysqli_error($connection)."</p>";
header("location: memberOrders.php?error=$error");
exit;
}
}
There is also no sqli_error. The output from this code (when $clear = TRUE) is:
Unable to execute CLEAR ALL query.
Error code :
Any help would be much appreciated.
Regards,
DLW
/********************** PROBLEM CODE **********************/
if (!empty($deleteFilm)) {
$sqlString = "DELETE FROM orders WHERE dvd = '$deleteFilm' and customer = '$usrName';";
if ($queryResult = @mysqli_query($connection, $sqlString)) {
$msg = "The item has been removed from your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
else {
$error = "<p>Unable to execute DELETE ORDER query."
. "<br />Error code " . mysqli_errno($connection)
. ":" . mysqli_error($connection)."</p>";
header("location: memberOrders.php?error=$error");
exit;
}
}
else if (!empty($addFilm)) {
$sqlString = "INSERT INTO orders VALUES ('$addFilm', '$usrName');";
if($queryResult = @mysqli_query($connection, $sqlString)) {
$msg = "The item has been added to your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
else {
$error = "<p>Unable to execute ADD FILM query."
. "<br />Error code " . mysqli_errno($connection)
. ":" . mysqli_error($connection)."</p>";
header("location: memberOrders.php?error=$error");
exit;
}
}
else if($clear) {
$sqlString = "DELETE FROM orders WHERE customer = '$usrName';";
if ($queryResult = @mysqli_query($connection, $sqlString)) {
$msg = "All items have been removed from your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
else {
$error = "<p>Unable to execute CLEAR ALL query."
. "<br />Error code " . mysqli_errno($connection)
. ":" . mysqli_error($connection)."</p>";
header("location: memberOrders.php?error=$error");
exit;
}
}