What is the potential issue when updating database fields in PHP and how can it be avoided?

When updating database fields in PHP, a potential issue is SQL injection attacks if user input is not properly sanitized. To avoid this, always use prepared statements with parameterized queries to securely pass user input to the database.

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL statement with a parameterized query
$stmt = $pdo->prepare("UPDATE mytable SET myfield = :value WHERE id = :id");

// Bind parameters and execute the statement
$stmt->bindParam(':value', $value);
$stmt->bindParam(':id', $id);
$stmt->execute();