$field) { if (preg_match('~char|text|set~', $field["type"]) ? $_POST["null"][$key] : !strlen($_POST["fields"][$key])) { $value = "NULL"; } elseif ($field["type"] == "enum") { $value = intval($_POST["fields"][$key]); } elseif ($field["type"] == "set") { $value = array_sum((array) $_POST["fields"][$key]); } else { $value = "'" . mysql_real_escape_string($_POST["fields"][$key]) . "'"; } $set[] = idf_escape(bracket_escape($key, "back")) . " = $value"; } if ($where) { $query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"; $message = lang('Item has been updated.'); } else { $query = "INSERT INTO " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set); $message = lang('Item has been inserted.'); } } if (mysql_query($query)) { redirect($SELF . "select=" . urlencode($_GET["edit"]), $message); } $error = mysql_error(); } page_header(($_GET["where"] ? lang('Edit') : lang('Insert')) . ": " . htmlspecialchars($_GET["edit"])); echo "
" . lang('Error during saving') . ": " . htmlspecialchars($error) . "
\n"; $data = $_POST["fields"]; foreach ($_POST["fields"] as $key => $val) { $data[$key] = null; } } elseif ($where) { $select = array("*"); foreach ($fields as $name => $field) { if ($field["type"] == "enum" || $field["type"] == "set") { $select[] = "1*" . idf_escape($name) . " AS " . idf_escape($name); } } $data = mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1")); } else { $data = array(); } ?>