What are the potential pitfalls of using onclick attribute in HTML for PHP functions?

Using the onclick attribute in HTML to call PHP functions can expose your code to security risks such as cross-site scripting (XSS) attacks. To avoid this, it's recommended to use AJAX to make requests to a separate PHP file that contains the function you want to execute.

// HTML code with AJAX call
<button onclick="callPHPFunction()">Click me</button>
<script>
function callPHPFunction() {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', 'your_php_file.php', true);
  xhr.send();
}
</script>

// your_php_file.php
<?php
// Your PHP function code here
?>