What are the potential security risks of not sanitizing input data, such as post IDs, in PHP scripts?

Not sanitizing input data in PHP scripts can lead to security vulnerabilities such as SQL injection, cross-site scripting (XSS), and other forms of attacks. To prevent these risks, it is crucial to sanitize input data by validating and filtering user input before using it in SQL queries or displaying it on a webpage.

// Sanitize input data using filter_var function
$post_id = filter_var($_POST['post_id'], FILTER_SANITIZE_NUMBER_INT);