SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: textarea \n = new record
-
May 14, 2005, 13:22 #1
textarea \n = new record
I would like to enter email addresses into an text area, each address seperated by a new line. Then , each address will become it's own record.
so, if I enter into the text area
email01@foo.com
email02@foo.com
in the db each email address has it's own record
id = 1, email = email01@foo.com
id = 2, email = email02@foo.com
What's the best way to do this?
Thanks!
-
May 14, 2005, 13:27 #2
- Join Date
- Apr 2001
- Location
- Canada
- Posts
- 5,458
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$emails = split("\n", $userinput);
foreach($emails as $email)
{
// insert
}
Mike
It's not who I am underneath, but what I do that defines me.
-
May 14, 2005, 13:28 #3
- Join Date
- Mar 2003
- Location
- England, UK
- Posts
- 2,906
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Something like:
PHP Code:$emails = preg_split('/[\r\n]+/', $_POST['emails']);
foreach($emails AS $email)
{
mysql_query("INSERT INTO table (somefield) VALUES ('" . mysql_real_escape_string($email) . "')");
}
-
May 14, 2005, 13:54 #4
Thanks guys, that was perfect!
Bookmarks