$id]; // قائمة الحقول القابلة للتحديث $fields = [ "start_location", "end_location", "date", "time", "endtime", "price", "passenger_id", "driver_id", "status", "created_at", "updated_at", "rideTimeStart", "rideTimeFinish", "price_for_driver", "driverGoToPassengerTime", "price_for_passenger", "distance" ]; // بناء الاستعلام ديناميكياً باستخدام filterRequest foreach ($fields as $field) { // نتحقق من وجود المفتاح في الـ POST if (isset($_POST[$field])) { // نستخدم دالة الفلترة الخاصة بك $value = filterRequest($field); $columnValues[] = "`$field` = :$field"; $params[":$field"] = $value; } } // إذا لم يتم إرسال أي حقول للتحديث if (empty($columnValues)) { error_log("⚠️ [update.php] No data provided in request to update."); jsonError("No data provided for update."); exit; } // تجميع جملة SQL $setClause = implode(", ", $columnValues); $sql = "UPDATE `ride` SET $setClause WHERE `id` = :id"; try { // --------------------------------------------------------- // 1. التحديث على سيرفر التتبع (Remote DB) - هو الأساس // --------------------------------------------------------- error_log("🔄 [update.php] Attempting to update REMOTE Tracking DB for Ride ID: $id"); $stmtRemote = $con_ride->prepare($sql); $stmtRemote->execute($params); $count = $stmtRemote->rowCount(); error_log("ℹ️ [update.php] Remote DB Rows Affected: $count"); // التحقق: هل نجح التحديث هناك؟ if ($count > 0) { // --------------------------------------------------------- // 2. التحديث على السيرفر المحلي (Local DB) للمطابقة // --------------------------------------------------------- error_log("🔄 [update.php] Remote success. Updating LOCAL Main DB..."); $stmtLocal = $con->prepare($sql); $stmtLocal->execute($params); error_log("✅ [update.php] Update successful on both servers."); // استخدام دالة النجاح الخاصة بك jsonSuccess(null, "Ride data updated successfully"); } else { // لم يتم التحديث (إما البيانات نفسها لم تتغير، أو المعرف غير موجود في السيرفر البعيد) error_log("⚠️ [update.php] Remote Update returned 0 rows (Data same or ID not found)."); // استخدام دالة الفشل (يمكنك تغيير الرسالة لتكون success إذا كنت لا تعتبر عدم تغيير البيانات خطأ) jsonError("No changes made (Remote DB affected 0 rows). Check ID or Data."); } } catch (PDOException $e) { error_log("❌ [update.php] Database Error: " . $e->getMessage()); jsonError("Database Error"); } ?>