What is the potential risk of SQL injection in the provided PHP code?

The potential risk of SQL injection in the provided PHP code is that user input is directly concatenated into the SQL query without any sanitization or validation, making it vulnerable to malicious SQL injection attacks. To prevent this, you should use prepared statements with parameterized queries to separate the SQL query from the user input, thus protecting against SQL injection attacks.

// Original vulnerable code
$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($connection, $query);

// Fixed code using prepared statements
$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM users WHERE username=? AND password=?";
$stmt = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt, "ss", $username, $password);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);