begin_transaction(); try { // Prepare the SQL update statement $stmt = $conn->prepare("UPDATE membership_application SET first_name = ?, last_name = ?, id_number = ?, dob = ?, occupation = ?, tel_cell = ?, email = ?, spouse_first_name = ?, spouse_last_name = ?, spouse_id_number = ?, spouse_dob = ?, spouse_occupation = ?, spouse_tel_cell = ?, spouse_email = ?, child_name1 = ?, child_dob1 = ?, child_name2 = ?, child_dob2 = ?, child_name3 = ?, child_dob3 = ?, physical_address = ?, postal_address = ?, interests_hobbies = ?, vehicle_make = ?, vehicle_model = ?, vehicle_year = ?, vehicle_registration = ?, secondary_vehicle_make = ?, secondary_vehicle_model = ?, secondary_vehicle_year = ?, secondary_vehicle_registration = ? WHERE user_id = ?"); // Check if preparation was successful if (!$stmt) { die("SQL error: " . $conn->error); } $stmt->bind_param( "sssssssssssssssssssssssssssssssi", $first_name, $last_name, $id_number, $dob, $occupation, $tel_cell, $email, $spouse_first_name, $spouse_last_name, $spouse_id_number, $spouse_dob, $spouse_occupation, $spouse_tel_cell, $spouse_email, $child_name1, $child_dob1, $child_name2, $child_dob2, $child_name3, $child_dob3, $physical_address, $postal_address, $interests_hobbies, $vehicle_make, $vehicle_model, $vehicle_year, $vehicle_registration, $secondary_vehicle_make, $secondary_vehicle_model, $secondary_vehicle_year, $secondary_vehicle_registration, $user_id // User ID for WHERE condition ); if ($stmt->execute()) { $conn->commit(); header("Location: membership_details.php"); exit(); // Ensure no further code is executed after the redirect } else { throw new Exception("Failed to update member application. SQL error: " . $conn->error); } } catch (Exception $e) { // Rollback the transaction in case of error $conn->rollback(); // Error response $response = [ 'status' => 'error', 'message' => 'Error: ' . $e->getMessage() ]; } } ?>