if / else help

I have this little delete user script and was wondering how I could do something like this.

If the user was deleted successfully redirect to successfully-deleted-user.php

If the user was not deleted successfully redirect to failed-delete-user.php

Here is my script:

[php]<?php
include($_SERVER[‘DOCUMENT_ROOT’] . “/core/init.php”);

$id = intval($_GET[‘id’]);

$deleteuser = DB::getInstance()->delete(‘users’, array(
‘id’, ‘=’, $id
));

if ($deleteuser){
header(“Location:/admin/users/successfully-deleted-user.php”);
}

else {
header(“Location:/admin/users/failed-delete-user.php”);
}

?>[/php]

Any help would be appreciated.

cwd, did you solve this one yet? I noticed it in the unanswered list…

Yes, you should be able to do it this way.

Then only catch is you need to know what is inside the result variable $deleteuser.

The returned value is sometimes the count of the affected items which would give you a “1”
if one item was affected. This might be viewed as a true, but is not really. You should test the
results with a non-existed user to see what is returned and with an existing user and check
both of the returned values and then test for the correct values.

Hope that makes sense. Hopefully, you already solved it. Good luck

Sponsor our Newsletter | Privacy Policy | Terms of Service