Initial commit with updated Auth and media ignored
This commit is contained in:
29
ride/RegisrationCar/makeDefaultCar.php
Executable file
29
ride/RegisrationCar/makeDefaultCar.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?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.");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user