When user input is directly included in an SQL command, the application risks SQL injection attacks. For instance, consider this vulnerable code snippet:
$input_data = $_POST['user_input'];
mysql_query("INSERT INTO `table_name` (`field_name`) VALUES ('$input_data')");
A malicious user could submit data like sample'); DROP TABLE table_name;--
, resulting in:
INSERT INTO `table_name` (`field_name`) VALUES('sample'); DROP TABLE table_name;--'
How can developers secure their PHP applications against such threats?