Files
Siro/walletintaleq.intaleq.xyz/v2/main/serviceApp/editCarPlate.php
2026-06-11 18:22:59 +03:00

43 lines
1.4 KiB
PHP

<?php
include "../connect.php";
// Retrieve and sanitize input parameters
$driverId = filterRequest("driverId");
$carPlate = filterRequest("carPlate");
// Start a transaction
$con->beginTransaction();
try {
// Update CarRegistration table
$sqlUpdate = "UPDATE `CarRegistration` SET `car_plate` = :carPlate WHERE `driverID` = :driverId";
$stmtUpdate = $con->prepare($sqlUpdate);
$stmtUpdate->bindParam(':carPlate', $carPlate);
$stmtUpdate->bindParam(':driverId', $driverId);
$stmtUpdate->execute();
// Check if the update was successful
if ($stmtUpdate->rowCount() > 0) {
// Insert into carPlateEdit table
$sqlInsert = "INSERT INTO `carPlateEdit` (`driverId`, `carPlate`, `isEdit`) VALUES (:driverId, :carPlate, 1)";
$stmtInsert = $con->prepare($sqlInsert);
$stmtInsert->bindParam(':driverId', $driverId);
$stmtInsert->bindParam(':carPlate', $carPlate);
$stmtInsert->execute();
// Commit the transaction
$con->commit();
// Print a success message
printSuccess("Car plate updated and edit record inserted successfully");
} else {
// Rollback the transaction if update failed
$con->rollBack();
printFailure("Failed to update car plate. No matching record found.");
}
} catch (PDOException $e) {
// Rollback the transaction if any error occurred
$con->rollBack();
printFailure("An error occurred: " . $e->getMessage());
}
?>