Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mulitple submissions t the same time import into mysql?

Posted on 2011-02-20
7
Medium Priority
?
196 Views
Last Modified: 2012-05-11
what I am trying to do is grab multiple email addresses at the same time from the same form. I want to have multiple fields for the email addresses.
my question is, is it possible to post the same variable to my query at the same time?
like if the DB on has one row called `email` how would I post multiple emails at the same time? i can do it one at a time.
is it clear what I am asking about?
0
Comment
Question by:jaxbrian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
LAMASE earned 1000 total points
ID: 34939241
You can name your inputs like this

<input name="email[]" value="">
<input name="email[]" value="">
<input name="email[]" value="">

This will generate a request like

script.php?email[]=email@test.com&email[]=...
(the parentesis are encoded in the real url)

In this way you can read an array directly... for example in PHP you will receive an array that you can access with
$array_email = $_REQUEST['email']; // <- this is an array

or you can read the request string and do it by yourself.
0
 
LVL 2

Author Comment

by:jaxbrian
ID: 34939332
I am not sure I understand, I think I tried what you are saying to do but I have not been able to get it to work.
when I try to echo the array, it only says "array" I did this just as a test to see if there was any data there. when i submit the form with multiple emails it doesn't fail, it just doesn't insert them int to eh DB.


thank you, I will keep messing with it.
0
 
LVL 4

Expert Comment

by:LAMASE
ID: 34939422
Output you vars with
print_r($variable);

Open in new window


or

var_dump($variable);

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 11

Expert Comment

by:Ovid Burke
ID: 34940697
Do you want to put multiple email addresses into one field in your database table? Or do you want to put them into separate records (rows)?

0
 
LVL 2

Author Comment

by:jaxbrian
ID: 34948027
I need them to go into separate rows.

thanks for your time
B
0
 
LVL 11

Assisted Solution

by:Ovid Burke
Ovid Burke earned 1000 total points
ID: 34948385
Try:

 
<?php

if(isset($_POST['submit']) && $_POST['submit'] = "Submit") { // check the form is submitted
	
	unset($_POST['submit']); // destroy the submit button
	
	if(is_array($_POST['email'])) {
		
		$arr_emails = $_POST['email']; // array of email addresses from form
		
		$arr_reject = array(); // array to hold bad or malformed addresses
	
		foreach($arr_emails as $email) { // loop through the array
			if(!is_email($email)) { // if not a valid email...
				$arr_reject[] = $email; // ... add to rejected emails array
			} else { // or perform database insert
				@mysql_query("INSERT INTO _tablename (emailfield) VALUES ('$email')") or die(
				"ERROR INSERTING EMAIL ($email):<br />"
				. mysql_error());
			}
		}
		
		// print out rejected email addresses
		if(!empty($arr_reject)) { 
			echo "THE FOLLOWING EMAILS WERE REJECTED: <br />";
			foreach($arr_reject as $reject) {
				echo "- $reject <br />";	
			}
		}
		
	} else {
		
		echo "Please specify at least one email address.";	
	
	}
	
}

// functions to validate email addresses
function is_host($host) {
	$dns = checkdnsrr($host);
	if(!($dns == 1)) {
		return false;
	}
	return true;
}
function is_email($email) {
	if(!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
		return false;
	}
	list($userid, $domain) = explode("@", $email);
	$userid_array = explode(".", $userid);
	for($i = 0; $i < sizeof($userid_array); $i++) {
		if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $userid_array[$i])) {
    		return false;
    	}
	}
	if (!ereg("^\[?[0-9\.]+\]?$", $domain)) { 
    	$domain_array = explode(".", $domain);
    	if (sizeof($domain_array) < 2) {
       		return false;
    	}
    	for ($i = 0; $i < sizeof($domain_array); $i++) {
      		if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        		return false;
      		}
    	}
		if(!is_host($domain)) {
			return false;
		}
  	}
	return true;
}

?>

Open in new window

0
 
LVL 2

Author Comment

by:jaxbrian
ID: 35047422
I could not get that script to work for the submission of emails. I am going to award points for your help with this. I realize now that I really need three form fields to be imported to MySQL. $first, $last, and $email and I guess that is really a new question.
I have tried to work with a foreach() and I just cant seem to get that to work either

thank you for every ones help with this
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question