Help with PHP / MySQL code.?

D w

New member
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;
}
}
 
on your first section you perform two queries are they necessary. From what I can tell you check if the variable is empty if it isn't your delete from the database were their username and dvd match.
you then go on to query a second time to see if it was successful. You don't need to query the database to see if a query was successful.

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;
}

would become

if (!empty($deleteFilm)) {
$sqlString = "DELETE FROM orders WHERE dvd = '$deleteFilm' and customer = '$usrName';";
if ($sqlString == true) {
$msg = "The item has been removed from your orders.";
header("location: memberOrders.php?msg=$msg");
exit;
}
__________________________________________
$sqlString = "DELETE FROM orders WHERE customer = '$usrName';";

at the end of this line you have two ";" you only need 1

also I am going to look into this as I don't know if your telling it what to delete. your just sayign delete from this table were customer = "" I don't know if your missing a * symbol
 
Not too sure but try removing the @ symbol in your condition statements

if ($queryResult = @mysqli_query($connection, $sqlString)) {

to

if ($queryResult = mysqli_query($connection, $sqlString)) {

and see if it makes a difference
 
Back
Top