What are the potential pitfalls of directly displaying numerical data from a database in PHP without conversion?

Directly displaying numerical data from a database in PHP without conversion can lead to security vulnerabilities such as SQL injection attacks. To prevent this, it is important to properly sanitize and escape the data before displaying it on the webpage. This can be done using functions like mysqli_real_escape_string or prepared statements to ensure that the data is properly formatted and safe to display.

// Connect to database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Query database for numerical data
$result = $mysqli->query("SELECT numerical_data FROM table");

// Fetch and sanitize data before displaying
while ($row = $result->fetch_assoc()) {
    $numerical_data = htmlspecialchars($row['numerical_data']);
    echo $numerical_data;
}