What are the potential security risks associated with using the GET method in PHP for passing user input to SQL queries?

Using the GET method in PHP for passing user input to SQL queries can lead to SQL injection attacks, where malicious users can manipulate the input to execute unintended SQL queries. To prevent this, it is important to sanitize and validate user input before using it in SQL queries.

// Sanitize and validate user input before using it in SQL queries
$user_input = $_GET['user_input'];
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);

// Use prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $sanitized_input);
$stmt->execute();