diff --git a/database.inc.php b/database.inc.php
index 776960b0..27759685 100644
--- a/database.inc.php
+++ b/database.inc.php
@@ -8,16 +8,15 @@ if ($_POST && !$error) {
if (query_redirect("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'" : ""), $SELF . "db=" . urlencode($_POST["name"]), lang('Database has been created.'), !strlen($_GET["db"]))) {
$result = $mysql->query("SHOW TABLES");
while ($row = $result->fetch_row()) {
- if (!$mysql->query("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
+ if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
break;
}
}
$result->free();
if (!$row) {
$mysql->query("DROP DATABASE " . idf_escape($_GET["db"]));
- redirect(preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
}
- $error = htmlspecialchars($mysql->error);
+ query_redirect(queries(), preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'), !$row, false, $row);
}
} else {
if (!$_POST["collation"]) {
diff --git a/functions.inc.php b/functions.inc.php
index 33cd8726..18de4993 100644
--- a/functions.inc.php
+++ b/functions.inc.php
@@ -195,11 +195,14 @@ function redirect($location, $message = null) {
exit;
}
-function query_redirect($query, $location, $message, $redirect = true, $execute = true) {
+function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
global $mysql, $error, $SELF;
$id = "sql-" . count($_SESSION["messages"]);
- $sql = " " . lang('SQL command') . "
" . htmlspecialchars($query) . '
' . lang('Edit') . '';
- if ($execute && !$mysql->query($query)) {
+ $sql = ($query ? " " . lang('SQL command') . "
" . htmlspecialchars($query) . '
' . lang('Edit') . '' : "");
+ if ($execute) {
+ $failed = !$mysql->query($query);
+ }
+ if ($failed) {
$error = htmlspecialchars($mysql->error) . $sql;
return false;
}
@@ -209,6 +212,16 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
return true;
}
+function queries($query = null) {
+ global $mysql;
+ static $queries = array();
+ if (!isset($query)) {
+ return implode("\n", $queries);
+ }
+ $queries[] = $query;
+ return $mysql->query($query);
+}
+
function remove_from_uri($param = "") {
$param = "($param|" . session_name() . ")";
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
diff --git a/processlist.inc.php b/processlist.inc.php
index 4175f151..683cfda0 100644
--- a/processlist.inc.php
+++ b/processlist.inc.php
@@ -2,14 +2,11 @@
if ($_POST && !$error) {
$killed = 0;
foreach ((array) $_POST["kill"] as $val) {
- if ($mysql->query("KILL " . intval($val))) {
+ if (queries("KILL " . intval($val))) {
$killed++;
}
}
- if ($killed || !$_POST["kill"]) {
- redirect($SELF . "processlist=", lang('%d process(es) has been killed.', $killed));
- }
- $error = htmlspecialchars($mysql->error);
+ query_redirect(queries(), $SELF . "processlist=", lang('%d process(es) has been killed.', $killed), $killed || !$_POST["kill"], false, !$killed && $_POST["kill"]);
}
page_header(lang('Process list'), $error);
?>
diff --git a/select.inc.php b/select.inc.php
index ef39cc2d..ccf75a68 100644
--- a/select.inc.php
+++ b/select.inc.php
@@ -66,7 +66,7 @@ if ($_POST && !$error) {
dump_table($_GET["select"], "");
}
if (isset($_POST["truncate"])) {
- $result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
+ $result = queries($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
$deleted = $mysql->affected_rows;
} elseif ($_POST["export_result"]) {
dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : ""));
@@ -76,7 +76,7 @@ if ($_POST && !$error) {
if ($_POST["export"]) {
dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
} else {
- $result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
+ $result = queries("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
if (!$result) {
break;
}
@@ -90,7 +90,7 @@ if ($_POST && !$error) {
$result1 = $mysql->query("SELECT * $from");
while ($row1 = $result1->fetch_assoc()) {
parse_str(implode("&", unique_idf($row1, $indexes)), $delete);
- $result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
+ $result = queries("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
if (!$result) {
break;
}
@@ -102,10 +102,7 @@ if ($_POST && !$error) {
if ($_POST["export"] || $_POST["export_result"]) {
exit;
}
- if ($result) {
- redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted));
- }
- $error = htmlspecialchars($mysql->error);
+ query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted), $result, false, !$result);
}
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : ""));