Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Adding multiple (comma-delimited) values from a single call?

PHP + MySQL help needed

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

New User

5+ Year Member

joined:Jan 1, 2007
posts: 24
votes: 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)

Full Member

10+ Year Member

joined:Feb 24, 2005
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members