What are the consequences of using unfiltered PHP data for IDs and names in HTML?

Using unfiltered PHP data for IDs and names in HTML can lead to security vulnerabilities such as cross-site scripting (XSS) attacks. To prevent this, it is important to properly sanitize and validate user input before using it in HTML attributes. This can be done by using functions like htmlspecialchars() to encode special characters.

```php
// Sanitize and validate user input before using it in HTML attributes
$id = htmlspecialchars($_POST['id']);
$name = htmlspecialchars($_POST['name']);
```

This code snippet demonstrates how to sanitize user input for an ID and name before using them in HTML attributes.