What security measures should be implemented when inserting user-submitted data into a MySQL database in PHP?

When inserting user-submitted data into a MySQL database in PHP, it is important to implement security measures to prevent SQL injection attacks. One way to do this is by using prepared statements with parameterized queries. This helps to separate the SQL query from the user input, making it impossible for an attacker to inject malicious code into the query.

// Assuming $conn is the MySQL database connection
$stmt = $conn->prepare("INSERT INTO table_name (column1, column2) VALUES (?, ?)");
$stmt->bind_param("ss", $userInput1, $userInput2);

$userInput1 = $_POST['input1'];
$userInput2 = $_POST['input2'];

$stmt->execute();
$stmt->close();