How can the SQL syntax error related to md5() function usage be resolved in a PHP script for user registration?

The SQL syntax error related to the md5() function usage in a PHP script for user registration can be resolved by properly escaping the hashed password before inserting it into the SQL query. This can be achieved by using prepared statements with placeholders to securely insert data into the database.

// Assuming $username and $password are already defined

// Connect to the database
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

// Prepare the SQL statement with placeholders
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");

// Hash the password using md5() function
$hashed_password = md5($password);

// Bind the parameters and execute the statement
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $hashed_password);
$stmt->execute();