<?php include './core/bootstrap.php'; //connect to database include 'dbconnect.php'; //check that user has a valid cookie, redirect if no valid cookie include 'php_common/cookiecheck.php'; $workoutLoggingService = new WorkoutLoggingService(); $userService = new UserService(); $climbingAreaService = new ClimbingAreaService(); $workout_id_prev = $_GET['wid']; $showChangesSaved = 0; //check if edits have been submitted if (isset($_POST['workoutsubmit'])) { // save workout as a new workout (even though it was edited) $workoutResult = $workoutLoggingService->saveWorkout($_POST, $userid); // delete the previous workout $workoutLoggingService->deleteWorkout($workout_id_prev); // reset previous workout id $workout_id_prev = $workoutResult["workoutID"]; //display a message that changes have been saved. $showChangesSaved = 1; //update records table include 'update-records-absolute.php'; } $workoutInfo = $workoutLoggingService->getWorkoutInfo($workout_id_prev); $userid_wid = $workoutInfo["userid"]; // Check that user of the workout_id_prev matches that of the cookie userid if ($userid != $userid_wid) { header('Location: past-workouts.php'); }