$memberID = null;
$processed = false;
$submissionKey = null;
$error = false;
$errorCode = 0;
try {
    $dbConnection = DatabaseUtilities::getDatabaseConnection();
    //Get the current user's ID and details.
    $memberID = LoginController::getLoggedInMemberID($dbConnection);
    if ($memberID == null) {
        header("Location: login.php");
        exit;
    } else {
        if (isset($_GET['advertisementID'])) {
            $advertisementID = $_GET['advertisementID'];
            $memberDetails = MemberController::getMemberDetails($memberID, $dbConnection);
            //If member details or advertisement ID cannot be obtained then do not continue.
            if ($memberDetails != null && $advertisementID != null) {
                //Check that the user has the priviledge to edit the advertisement.
                $advertisementDetails = AdvertisementController::getAdvertisementForEdit($advertisementID, $memberID, $dbConnection);
                //If the advertisementDetails object is null then the user does not have the permissions to edit it.
                if ($advertisementDetails != null) {
                    $advertisementGenres = AdvertisementGenreController::getAdvertisementGenres($advertisementID, $dbConnection);
                    $advertisementPositions = AdvertisementPositiionController::getAdvertisementPositions($advertisementID, $dbConnection);
                    //Encrypt values to be validated on update.
                    $advertisementKey = EncryptionUtilities::encryptString($advertisementID . $memberID);
                    $memberIDEncrypted = EncryptionUtilities::encryptString($memberID);
                    //Generate a submission key to be used upon update.
                    $submissionKey = MemberSubmissionController::generateSubmissionKey($memberID, $dbConnection);
                    $processed = true;
                }