While searching I found this thread, which has gotten me further then I have so far. But I'm still having problems.
I want to take the information from a php textarea form and have it inserted into separate rows in a table. The input would be like this:
Bill
Jack
Steph
I've tried a few different methods. I haven't been getting errors, but it doesn't write to the database either. I tried the code from the thread above and when I submit it adds one or two blank rows to the table (doesn't matter how many entries I put in the textarea). A step forward, but still no good. Any help would be appreciated.
Here's my messy code:
<?php
$textarea = mysql_real_escape_string($_POST['textarea']);
$array = explode("\n", $textarea);
$i=0;
foreach ($array as $value) {
mysql_query("INSERT INTO random_prompts (prompt) VALUES ('{$array[$i]}')") or die(mysql_erorr());
$i++;
}
?>
<h2>Data Import</h2>
<form methods="post" action="">
Data: <textarea name="textarea" rows="20" cols="30"</textarea>
<input type="submit" name="submit" value="Import History">
</form>