What are some potential pitfalls to avoid when creating a download counter script in PHP?

One potential pitfall to avoid when creating a download counter script in PHP is not properly sanitizing user input, which could lead to security vulnerabilities such as SQL injection attacks. To solve this issue, always use prepared statements when interacting with a database to prevent SQL injection.

// Example of using prepared statements to prevent SQL injection
$download_id = $_GET['id'];
$stmt = $pdo->prepare("UPDATE downloads SET count = count + 1 WHERE id = :id");
$stmt->bindParam(':id', $download_id);
$stmt->execute();