What are the potential security risks associated with not using mysql_real_escape_string for database interactions?

When not using mysql_real_escape_string for database interactions, there is a risk of SQL injection attacks where malicious code can be injected into SQL queries, potentially leading to unauthorized access or manipulation of the database. To prevent this, it is important to properly escape user input before including it in SQL queries.

// Using mysql_real_escape_string to escape user input before including it in SQL queries
$user_input = $_POST['user_input'];
$escaped_user_input = mysql_real_escape_string($user_input);

$query = "SELECT * FROM users WHERE username='$escaped_user_input'";
$result = mysql_query($query);