function updatepic($action, $db, $userid)
{
    $suffix = " FROM `profilepic` WHERE `id` = '" . $userid . "'";
    switch ($action) {
        case "get":
            $prefix = "SELECT url";
            break;
        case "delete":
            $prefix = "DELETE";
            break;
        default:
            // in case of "ADD" the $action is actually the URL
            $prefix = "INSERT INTO `passgame`.`profilepic` (`id`, `url`) VALUES (" . $userid . ", '" . $action . "');";
            $suffix = "";
            if (updatepic("get", $db, $userid)) {
                updatepic("delete", $db, $userid);
            }
    }
    $sql = $prefix . $suffix;
    $createsql = "CREATE TABLE IF NOT EXISTS `passgame`.`profilepic` ( `id` INT NOT NULL , `url` VARCHAR(512) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;";
    $createresult = mysqli_query($db, $createsql) or trigger_error("error: " . mysqli_error($db), E_USER_ERROR);
    $result = mysqli_query($db, $sql) or trigger_error("error: " . mysqli_error($db), E_USER_ERROR);
    if (@mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        mysqli_free_result($result);
        return $row['url'];
    } else {
        // if there is a result but no rows found, added, or deleted
        return FALSE;
    }
}
                    displayupdatepic($displayname);
                }
                mysqli_close($db);
            }
            echo '<input type="hidden" name="whatever" value="' . $pw . '">';
            echo '<input type="hidden" name="userid" value="' . $userid . '">';
        }
    } else {
        createdisplayname($db, $userid, $displayname);
        displayupdatepic($displayname);
        echo '<input type="hidden" name="whatever" value="' . $pw . '">';
        echo '<input type="hidden" name="userid" value="' . $userid . '">';
    }
} else {
    include $INC_DIR . "updatepic.php";
    $result = updatepic($profilepic, $db, $userid);
    echo '<br><img src="' . $profilepic . '" id="profilepicture"><h1>' . $displayname . '</h1>';
    displayupdatepic($displayname);
    echo '<input type="hidden" name="profilepic" value="' . $profilepic . '">';
    echo '<input type="hidden" name="whatever" value="' . $pw . '">';
    echo '<input type="hidden" name="userid" value="' . $userid . '">';
}
?>
<input class="button" type="submit" id="formsubmit">
</form>
<?php 
if (isset($_POST['profilepic'])) {
    echo '<a href="javascript:hidebox();" class="button" id="closebox" onclick="hidebox()">X</a>';
}
if (isset($_POST['whatever'])) {
    echo '[<a href="index.php">logout</a>]';