What are the potential pitfalls of using JavaScript to display error messages in PHP scripts?

One potential pitfall of using JavaScript to display error messages in PHP scripts is that it may not work for users who have JavaScript disabled in their browsers. To ensure that error messages are displayed regardless of JavaScript availability, you can use PHP to output error messages directly in the HTML response.

<?php
// PHP script to display error messages without relying on JavaScript

// Check for errors
if ($error) {
    echo '<p class="error">' . $error_message . '</p>';
}
?>