What potential issues can arise when using $_GET variables in PHP?

One potential issue when using $_GET variables in PHP is the risk of SQL injection attacks if the input is not properly sanitized. To solve this issue, always sanitize and validate user input before using it in SQL queries to prevent malicious code execution.

// Sanitize and validate the $_GET variable before using it in a SQL query
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$id = filter_var($id, FILTER_VALIDATE_INT);

// Use the sanitized variable in your SQL query
$query = "SELECT * FROM users WHERE id = $id";
$result = mysqli_query($conn, $query);