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