What are the potential pitfalls of executing MySQL queries from a textarea input in PHP?

Executing MySQL queries directly from a textarea input in PHP can lead to SQL injection attacks, where malicious code is inserted into the query to manipulate the database. To prevent this, it is essential to sanitize and validate the input before executing any queries.

// Sanitize the textarea input before using it in a MySQL query
$text = $_POST['textarea_input'];
$clean_text = mysqli_real_escape_string($connection, $text);

// Execute the sanitized query
$query = "SELECT * FROM table WHERE column = '$clean_text'";
$result = mysqli_query($connection, $query);