Initial commit with updated Auth and media ignored
This commit is contained in:
42
ride/notificationPassenger/update.php
Normal file
42
ride/notificationPassenger/update.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
$fields = [];
|
||||
$params = [':id' => $id];
|
||||
|
||||
$mapping = [
|
||||
"title" => "title",
|
||||
"body" => "body",
|
||||
"passengerID" => "passenger_id",
|
||||
"isShown" => "isShown",
|
||||
"updatedAt" => "updated_at"
|
||||
];
|
||||
|
||||
// تجهيز الـ SET والأرقام المقابلة
|
||||
foreach ($mapping as $requestKey => $dbColumn) {
|
||||
if (isset($_POST[$requestKey])) {
|
||||
$value = filterRequest($requestKey);
|
||||
$fields[] = "`$dbColumn` = :$requestKey";
|
||||
$params[":$requestKey"] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($fields)) {
|
||||
jsonError("No fields to update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$setClause = implode(", ", $fields);
|
||||
$sql = "UPDATE `notifications` SET $setClause WHERE `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Notification data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update notification data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user