$start_location, ":end_location" => $end_location, ":date" => $date_formatted, // نستخدم الصيغة المعالجة ":time" => $time_formatted, // نستخدم الصيغة المعالجة ":endtime" => $endtime_formatted, ":price" => $price, ":passenger_id" => $passenger_id, ":driver_id" => $driver_id, ":status" => $status, ":carType" => $carType, ":price_for_driver" => $price_for_driver, ":price_for_passenger" => $price_for_passenger, ":distance" => $distance, ]; // تسجيل البيانات التي سيتم إدخالها للتأكد error_log("ℹ️ [add_ride.php] Prepared Data: " . json_encode($data)); // --------------------------------------------------------- // 3. الإضافة في السيرفر المحلي (Main DB) // --------------------------------------------------------- $sql = "INSERT INTO `ride` ( `start_location`, `end_location`, `date`, `time`, `endtime`, `price`, `passenger_id`, `driver_id`, `status`, `carType`, `price_for_driver`, `price_for_passenger`, `distance` ) VALUES ( :start_location, :end_location, :date, :time, :endtime, :price, :passenger_id, :driver_id, :status, :carType, :price_for_driver, :price_for_passenger, :distance )"; try { error_log("🔄 [add_ride.php] Inserting into LOCAL DB..."); $stmt = $con->prepare($sql); $stmt->execute($data); $insertedId = $con->lastInsertId(); $count = $stmt->rowCount(); error_log("✅ [add_ride.php] Local Insert Success. ID: $insertedId"); if ($count > 0) { // --------------------------------------------------------- // 4. الإضافة في سيرفر التتبع (Tracking DB) // --------------------------------------------------------- $sqlRemote = "INSERT INTO `ride` ( `id`, `start_location`, `end_location`, `date`, `time`, `endtime`, `price`, `passenger_id`, `driver_id`, `status`, `carType`, `price_for_driver`, `price_for_passenger`, `distance` ) VALUES ( :id, :start_location, :end_location, :date, :time, :endtime, :price, :passenger_id, :driver_id, :status, :carType, :price_for_driver, :price_for_passenger, :distance )"; // إضافة الـ ID للمصفوفة $data[':id'] = $insertedId; try { error_log("🔄 [add_ride.php] Inserting into REMOTE DB..."); $stmtRemote = $con_ride->prepare($sqlRemote); $stmtRemote->execute($data); error_log("✅ [add_ride.php] Remote Insert Success."); } catch (PDOException $eRemote) { // نسجل خطأ الريموت لكن لا نوقف العملية لأن اللوكل تم بنجاح error_log("⚠️ [add_ride.php] Remote DB Error: " . $eRemote->getMessage()); } // طباعة النجاح (JSON صحيح) jsonSuccess($insertedId); } else { error_log("❌ [add_ride.php] Failed to insert locally (Rows affected 0)."); jsonError("Failed to save ride information locally"); } } catch (PDOException $e) { // تسجيل الخطأ بدقة error_log("❌ [add_ride.php] SQL Error: " . $e->getMessage()); jsonError("Database Error: " . $e->getMessage()); } ?>