beginTransaction(); try { // 1. Update the message content $stmt = $pdo->prepare("UPDATE messages SET content = ? WHERE id = ?"); $stmt->execute([$content, $messageId]); // 2. Update the schedule // When editing, we reset its status to 'pending' so the worker can pick it up again. $stmt = $pdo->prepare( "UPDATE schedules SET recipient_id = ?, send_time = ?, status = 'pending' WHERE id = ?" ); $stmt->execute([$recipientId, $scheduleDateTime, $scheduleId]); $pdo->commit(); // Redirect to a success page header('Location: ../scheduled_messages.php?success=updated'); exit(); } catch (Exception $e) { $pdo->rollBack(); error_log("Message update failed: " . $e->getMessage()); header('Location: ../edit_message.php?schedule_id=' . $scheduleId . '&error=dberror'); exit(); } ?>