processing lines in a form

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a multi line form that lets users paste in addresses for our
internal mailing lists --- 30 to 50 addresses is average. I want to be
able to add all of the names into the mysql table by looping through the
list and adding each name after the form is posted. I am unable to
locate a tutorial on getting this to work, so I suppose there must be a
better way to do this without uploading a text file. Does anyone know
how to do this in php?

Re: processing lines in a form

brian cole wrote:
Quoted text here. Click to load it

How is the form set up? Is each address entered in a separate text box
or is all of the text typed in on textarea? It makes a difference when
it comes to writing the PHP to process the information.


Re: processing lines in a form

brian cole wrote [edited]:
Quoted text here. Click to load it

This is the script that receives your form submittal:

/* let's say your textarea is named "addresses" */
foreach (explode("\n", $_POST['addresses']) as $line) {
  /* validate and add line (hopefully with ONE address) to an array */
  $addr_to_mysql[] = mysql_escape_string(validate($line));

/* You now have an array with addresses */
$sql  = "insert into mailing_list (addr) values ('";

/* use it to build the SQL command string */
$sql .= implode("', '", $addr_to_mysql);

$sql .= "')";

/* Just send the $sql to your database server */
echo $sql;
Mail to my "From:" address is readable by all at /
== ** ## !! ------------------------------------------------ !! ## ** ==
may bypass my spam filter. If it does, I may reply from another address!

Site Timeline