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()); } ?>