mforan Posted August 10, 2010 Share Posted August 10, 2010 Hi there, im having bit of a problem with this foreach.... as far as i can see i think its right? no doubt something is horribly wrong... lol. anyone have any idea? (post email would be for example "[email protected], [email protected]") ((which makes sense since this SHUD be arrayable???)) <?php $emails = preg_replace("[^a-z0-9\@\.\_\-]", "", $_POST["email"]); $emailArray = explode(",",$emails); foreach($emailArray As $emails[0]){ $query = "SELECT count(email) FROM buddyp WHERE email='$emails[0]'"; $result = mysql_query($query) or die("Error: ".mysql_error()); $emailc = mysql_fetch_array($result, MYSQL_NUM); if ($emailc[0] == 0) { $query = "INSERT INTO buddyp SET email='$emails[0]',day='".time()."'"; mysql_query($query) or die("Error: ".mysql_error()); // message $message = 'EMAIL CONTENTS'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Ambroid <[email protected]>' . "\r\n"; // Mail it mail($emails[0], "AMBROID - The War Game", $message, $headers); $exc = "Emails were sent to: $emails[0]"; } else { $exc = "ERROR: You cannot invite the same person to the game within a 3 day period!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210382-foreach-problem/ Share on other sites More sharing options...
freeloader Posted August 10, 2010 Share Posted August 10, 2010 What do you want it to do and what is the output it's generating? Quote Link to comment https://forums.phpfreaks.com/topic/210382-foreach-problem/#findComment-1097853 Share on other sites More sharing options...
mforan Posted August 11, 2010 Author Share Posted August 11, 2010 very simple. input is 2 or more email address separated by commas... output is an email message sent to both the 2 or more email address's, providing they have not been used within the last 3 days (i have another bit of code for that crap) Quote Link to comment https://forums.phpfreaks.com/topic/210382-foreach-problem/#findComment-1097859 Share on other sites More sharing options...
freeloader Posted August 11, 2010 Share Posted August 11, 2010 Why are you doing this: foreach($emailArray As $emails[0]) shouldn't that be: foreach($emailArray As $emails) ? foreach (array_expression as $key => $value) remember Quote Link to comment https://forums.phpfreaks.com/topic/210382-foreach-problem/#findComment-1097869 Share on other sites More sharing options...
mforan Posted August 11, 2010 Author Share Posted August 11, 2010 DOH! of course, lmfao. thanks mate, such an obvious one that i just "overlooked" lol! Quote Link to comment https://forums.phpfreaks.com/topic/210382-foreach-problem/#findComment-1098239 Share on other sites More sharing options...
freeloader Posted August 11, 2010 Share Posted August 11, 2010 Np, glad it's solved Quote Link to comment https://forums.phpfreaks.com/topic/210382-foreach-problem/#findComment-1098298 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.