How can field names in SQL statements be properly escaped to prevent injection attacks in PHP?

To prevent SQL injection attacks in PHP, field names in SQL statements can be properly escaped by using backticks (`) around the field names. This ensures that the field names are treated as literals and not as executable SQL code.

// Example of properly escaping field names in an SQL statement
$field_name = "user_input"; // Field name provided by user input
$escaped_field_name = "`" . $field_name . "`"; // Escaping the field name with backticks

$sql = "SELECT * FROM table_name WHERE " . $escaped_field_name . " = 'some_value'";