59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
include "../../connect.php";
|
|
|
|
// استلام البيانات من Flutter
|
|
$driver_id = filterRequest("driver_id");
|
|
$trip_id = filterRequest("trip_id");
|
|
$max_speed = filterRequest("max_speed");
|
|
$avg_speed = filterRequest("avg_speed");
|
|
$hard_brakes = filterRequest("hard_brakes");
|
|
$total_distance = filterRequest("total_distance");
|
|
$behavior_score = filterRequest("behavior_score");
|
|
|
|
// تحقق من القيم الأساسية
|
|
if (empty($driver_id) || empty($trip_id)) {
|
|
// Log the validation error
|
|
error_log("Driver Behavior Error: Missing driver_id ($driver_id) or trip_id ($trip_id)");
|
|
printFailure("Missing driver_id or trip_id");
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
// إدخال البيانات في جدول driver_behavior
|
|
$stmt = $con->prepare("
|
|
INSERT INTO driver_behavior (
|
|
driver_id, trip_id, max_speed, avg_speed,
|
|
hard_brakes, total_distance, behavior_score
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
");
|
|
|
|
$stmt->execute([
|
|
$driver_id,
|
|
$trip_id,
|
|
$max_speed,
|
|
$avg_speed,
|
|
$hard_brakes,
|
|
$total_distance,
|
|
$behavior_score
|
|
]);
|
|
|
|
// التحقق من نجاح العملية
|
|
if ($stmt->rowCount() > 0) {
|
|
printSuccess("Behavior data saved");
|
|
} else {
|
|
// Log that the query ran but no rows were inserted
|
|
error_log("Driver Behavior Warning: Insert executed but 0 rows affected for driver $driver_id");
|
|
printFailure("Failed to save data");
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
// --- THIS IS THE TYPE ERROR LOG YOU ASKED FOR ---
|
|
// This records the exact SQL error (e.g., duplicate entry, foreign key fail) to your server log
|
|
error_log("Driver Behavior SQL Error: " . $e->getMessage());
|
|
|
|
// Return a generic error to the app (or $e->getMessage() if debugging)
|
|
printFailure("Database Error");
|
|
}
|
|
|
|
exit();
|
|
?>
|