Beispiel #1
0
    foreach ($valid_authors as $fields) {
        if (!$fields['isValid']) {
            $isFormValid = false;
            break;
        }
    }
}
if (array_key_exists('create_submit', $_POST)) {
    if ($isFormValid) {
        add_author($valid_authors[WRITER]['value'], $valid_authors[ARTIST]['value']);
        header('Location: index.php');
        exit;
    }
} elseif (array_key_exists('edit_submit', $_POST)) {
    if ($isFormValid) {
        update_author($_GET['id'], $valid_authors[WRITER]['value'], $valid_authors[ARTIST]['value']);
        $isUpdated = true;
    }
} elseif (array_key_exists('delete_submit', $_POST)) {
    delete_author($_GET['id']);
    header('Location: index.php');
    exit;
} elseif (array_key_exists('close_submit', $_POST)) {
    header('Location: index.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
// process post actions
// insert author
if (isset($_POST['add_author']) && $_POST['add_author'] == 'add') {
    $insert_status = insert_author();
    if (is_int($insert_status)) {
        $reload = $_SERVER["PHP_SELF"] . '?page_name=authors&author_id=' . $insert_status;
        header('Location: ' . $reload);
        echo $reload;
    } else {
        $insert_error = $insert_status;
    }
}
// update author
if (isset($_POST['update_author']) && $_POST['update_author'] == 'update') {
    $author_id = (int) $_GET['author_id'];
    $update_status = update_author($author_id);
    if ($update_status === true) {
        header('Location: ' . $url);
    } else {
        $error = $update_status;
    }
}
// change password
if (isset($_POST['change_password']) && $_POST['change_password'] == 'change') {
    $author_id = (int) $_GET['author_id'];
    $change_status = change_author_password($author_id);
    if ($change_status === true) {
        $reload = $_SERVER["PHP_SELF"] . '?page_name=authors&author_id=' . $author_id . '&passwordchanged';
        header('Location: ' . $reload);
    } else {
        $error = 'Error changing password: ' . $change_status;