The following should do about what you want:
<?php
$dbcnx = mysql_connect('localhost','dbname','dbuser');
if (!$dbcnx){
exit('<p>unable to connect with database server</p>');
}
if (!@mysql_select_db('dbname')) {
exit('<p>unable to connect with database</p>');
}
//GET USER INPUT
$textarea = $_REQUEST['mytextarea'];
//SPLIT INPUT INTO RECORDS
$parts = explode(' | ',$textarea);
$records = array_chunk($parts,3);
//INSERT RECORDS TO DATABASE
if (count($records)>0)
{
foreach ($records as $record)
{
$string1 = mysql_real_escape_string($record[0]);
$string2 = mysql_real_escape_string($record[1]);
$string3 = mysql_real_escape_string($record[2]);
$sql = "INSERT INTO my_table SET string1='{$string1}',string2='{$string2}',string3='{$string3}'";
if (@mysql_query($sql)) {
echo '<p>record added!</p>';
}
else
{
echo '<p>ERROR: Could not insert a record!</p>';
exit();
}
}
}
?>
Notes: The above does not contain any checks to ensure that the data is going to be "correct". For example, suppose someone entered:
str1 | str2 | str3
str1 | str2 | str3
str1 | str2
You're missing one element off the end. This code won't account for this. So if this matters to you, you'll need to build in some checks to check for such things.
You could also combine all the query strings together to do one massive query (could be more efficient).
Also, it is fine to tell mySQL to output the error while testing/debugging, but you will want to remove it and replace it with a simple "error occurred" type message for public/production levels. Why? A malicious user can use info from the error message to try and manipulate your database! Hiding such info with a vague error message helps to protect you.
Further note, the command to "explode" your results from a string to an array will require it be in this format:
STR1 | STR2 | STR3 | STR1 | STR2 | STR3 | STR1 | STR2 | STR3 | STR1 | STR2 | STR3 | STR1 | STR2 | STR3 | STR1 | STR2 | STR3 | STR1 | STR2 | STR3 | STR1 | STR2 | STR3
(etc)
It cannot be on different lines/etc. You could get around this by incorporating an additional explode (first by line, then by pipe) or perhaps by a regular expression.