homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Adding multiple (comma-delimited) values from a single call?
PHP + MySQL help needed

 3:57 am on Dec 24, 2008 (gmt 0)

Here's my current code:

$query = "INSERT INTO `table` (`email`,`timestamp`) values ('".mysql_real_escape_string($email)."','$date')";
$result = mysql_query($query) or die(header('Location: /index.php?err=dupe_email'));
header('Location: /index.php?success=1');

It's a bit ugly (assumes any error = dupe email, as that's a unique field)

I have a very simple form where it just has a spot to put in an email, and a submit button.

When you submit, it adds the email to the db with a timestamp, and lets you know it was a success.

But how would I handle multiple emails? I would like to allow the user to put in a comma-delimited list of email addresses (e.g.
And add them all at the same time.

I don't need it to give an individual status update per email (e.g. "myemail@email.com already exists") when it's multiple, I just need to add them to the database.



 9:36 am on Dec 24, 2008 (gmt 0)


$emailArray = split(",", $emails);
foreach ($emailArray as $emailAddress)
$emailAddress = trim($emailAddress);
if ($emailAddress != "")
// Add to DB

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved