I need to know how to do the following using php coding please
- take inserted text from a textarea
- split the content per line
- Insert each line into the database as its own row with own id number
Can anyone show me how to do this please?
thanks
EDIT________
THis is what I have tried so Far
$is_first = true;
foreach (explode('\n', $_POST['code']) as &$voucher) {
if ($is_first) $is_first = false; else $query .= ', ';
$query .= '(' . mysql_real_escape($voucher) . ')';
mysql_query('INSERT INTO back_codes (`code_id`, `code`) VALUES (NULL, "$voucher")');
}
Refer to it using
$_POST['field_name'], if it has been sent with POST request, like that:You can split strings using
explode(), like that:Iterate through result of
explode()and then insert rows one-by-one to the database.