What are the consequences of not properly escaping user input in a MySQL query in PHP?

If user input is not properly escaped in a MySQL query in PHP, it can lead to SQL injection attacks where malicious code is injected into the query, potentially allowing attackers to access or manipulate the database. To prevent this, you should always use prepared statements and parameterized queries to properly escape user input.

// Using prepared statements to properly escape user input in a MySQL query
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();