What potential security vulnerabilities could be exploited in PHP code?
One potential security vulnerability in PHP code is SQL injection, where malicious SQL queries are injected into input fields to manipulate a database. To prevent this, you can use prepared statements with parameterized queries to sanitize user input and prevent SQL injection attacks.
// Using prepared statements to prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->execute(['username' => $username]);
$user = $stmt->fetch();