How can PHP be used to process data from a textarea and insert it into a database as separate entries?

To process data from a textarea and insert it into a database as separate entries, you can use PHP to split the textarea input into separate lines and then insert each line into the database as a separate entry. This can be achieved by using the explode() function to split the textarea input into an array of lines, and then iterating over each line to insert it into the database.

// Assuming you have already established a database connection

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $textarea_input = $_POST['textarea_input'];
    $lines = explode("\n", $textarea_input);
    
    foreach ($lines as $line) {
        $sql = "INSERT INTO your_table_name (column_name) VALUES ('$line')";
        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
    }
}