Skip to content
Snippets Groups Projects
Commit 17a81175 authored by Robert Anderson's avatar Robert Anderson
Browse files

Better SQL error handling

parent f8cda349
No related branches found
No related tags found
No related merge requests found
......@@ -72,49 +72,60 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
if (isset($_POST['confirm']) && $_POST['confirm'] == "yes") {
$db->beginTransaction();
# Delete user data
$res = $db->exec("DELETE FROM wisp_userdata WHERE UserID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
# Delete user attributes
$res = $db->exec("DELETE FROM user_attributes WHERE UserID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
# Delete group associations
$res = $db->exec("DELETE FROM ${DB_TABLE_PREFIX}users_to_groups WHERE UserID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
# Delete from users
$res = $db->exec("DELETE FROM users WHERE ID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
?>
<div class="notice">User with ID: <?php print_r($_POST['user_id']); ?> deleted!</div>
<div class="notice">Removed user data</div>
<?php
} else {
?>
<div class="warning">Failed to delete user data</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<?php
}
# Delete user attributes
$res = $db->exec("DELETE FROM user_attributes WHERE UserID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
?>
<div class="notice">Removed user attributes</div>
<?php
} else {
?>
<div class="warning">Failed to remove user attributes</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<?php
$db->commit();
} else {
}
# Delete group associations
$res = $db->exec("DELETE FROM ${DB_TABLE_PREFIX}users_to_groups WHERE UserID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
?>
<div class="warning">Failed to delete user!</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<div class="notice">Removed associated groups</div>
<?php
$db->rollback();
}
} else {
} else {
?>
<div class="warning">Failed to remove group associations</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<div class="warning">Failed to remove associated groups</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<?php
$db->rollback();
}
} else {
}
# Delete from users
$res = $db->exec("DELETE FROM users WHERE ID = ".$db->quote($_POST['user_id']));
if ($res !== FALSE) {
?>
<div class="warning">Failed to delete user attributes</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<div class="notice">Removed user</div>
<?php
$db->rollback();
}
} else {
?>
<div class="warning">Failed to delete user data</div>
<div class="warning">Failed to remove user</div>
<div class="warning"><?php print_r($res->errorInfo()); ?></div>
<?php
$db->rollback();
}
# Check if all is ok, if so, we can commit, else must rollback
......@@ -129,21 +140,17 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
<div class="notice">Changes reverted.</div>
<?php
}
} else {
?>
<div class="warning">Delete user aborted</div>
<?php
}
} else {
?>
<div class="warning">No user selected</div>
<?php
}
} else {
?>
<div class="warning">Invocation error</div>
<?php
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment