How can form input data be safely inserted into a MySQL database using PHP?

When inserting form input data into a MySQL database using PHP, it is important to sanitize the input to prevent SQL injection attacks. One way to do this is by using prepared statements with parameterized queries, which separate the SQL query from the user input. This ensures that the input data is treated as data rather than executable code.

// Assuming $conn is the MySQL database connection

// Sanitize and store form input data
$inputData = $_POST['input_data']; // Assuming 'input_data' is the form field name
$stmt = $conn->prepare("INSERT INTO table_name (column_name) VALUES (?)");
$stmt->bind_param("s", $inputData);
$stmt->execute();
$stmt->close();