What potential security risks should be considered when allowing users to input SQL queries directly into a webpage using PHP?

Allowing users to input SQL queries directly into a webpage using PHP can lead to SQL injection attacks, where malicious users can manipulate the input to execute unauthorized queries on the database. To prevent this, it is important to sanitize and validate user input before executing any SQL queries.

// Sanitize and validate user input before executing SQL query
$user_input = $_POST['user_input'];
$clean_input = mysqli_real_escape_string($connection, $user_input);

$sql = "SELECT * FROM users WHERE username = '$clean_input'";
$result = mysqli_query($connection, $sql);

// Rest of the code to handle the query result