Files
intaleq_v3_pure_php/ride/RegisrationCar/makeDefaultCar.php
2026-04-28 13:04:27 +03:00

29 lines
952 B
PHP
Executable File

<?php
require_once __DIR__ . '/../../connect.php';
$id = filterRequest("id");
$driverID = filterRequest("driverID");
try {
// أولاً: إعادة تعيين isDefault = 0 لكل سيارات السائق
$sql1 = "UPDATE `CarRegistration` SET `isDefault` = 0 WHERE `driverID` = :driverID";
$stmt1 = $con->prepare($sql1);
$stmt1->bindParam(':driverID', $driverID);
$stmt1->execute();
// ثانياً: تعيين السيارة المحددة كافتراضية
$sql2 = "UPDATE `CarRegistration` SET `isDefault` = 1 WHERE `id` = :id";
$stmt2 = $con->prepare($sql2);
$stmt2->bindParam(':id', $id);
$stmt2->execute();
if ($stmt2->rowCount() > 0) {
jsonSuccess(null, "Default car updated successfully.");
} else {
jsonError("Failed to update default car.");
}
} catch (PDOException $e) {
error_log("DB Error: " . $e->getMessage());
jsonError("Database error occurred.");
}
?>