PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old November 7th, 2002, 12:17 AM
theermine theermine is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 35 theermine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
parse error, unexpected T_FOREACH

I am trying to send email to a list of users from a Mysql DB and keep getting this error message.

Parse error: parse error, unexpected T_FOREACH, expecting ',' or ';' in

this is the chunk of code in question. Thanks for any help..
php Code:
Original - php Code
  1.  
  2. if($players = &$conn->Execute($query)===FALSE) {
  3.   echo "<p>Could not complete selection of players:<br/>n" .
  4.     $conn->ErrorNo() . ": " . $conn->ErrorMsg() . "</p>n";
  5. } else {
  6.   $playerlist = $players->GetRows();
  7.   // Send email in batches of 50
  8.   $i=1;
  9.   echo "<p>"
  10.  foreach($playerlist as $p) {
  11.     $to = $p["fullname"] . "<" . $p["email"] . ">";
  12.     if(mail($to, $subject, $message, $from)) {
  13.       echo "Mail successfully sent to $to<br/>";
  14.     } else {
  15.       echo "Mail to $to unsuccessful<br/>";
  16.     }
  17.     if(!($i%50)) {
  18.       sleep(5)
  19.     }
  20.     $i++;
  21.   }
  22. };

Reply With Quote
Old November 7th, 2002, 12:18 AM
theermine theermine is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 35 theermine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
RE: parse error, unexpected T_FOREACH

sorry, the line with "foreach($playerlist as $p) {" is the one the error message lists. Thanks again.

Reply With Quote
Old November 7th, 2002, 01:52 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
RE: parse error, unexpected T_FOREACH

you are missing ; in a line before foreach.

Reply With Quote
Old November 7th, 2002, 08:48 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,308 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 29
RE: parse error, unexpected T_FOREACH

Well shoot.. I can't find where.. Could you look at the entire script. Thanks for the help.

php Code:
Original - php Code
  1.  
  2. // Make sure we have a valid admin trying to access this file
  3. if($HTTP_SESSION_VARS["userID"]!=1) {
  4.   header("Location: " . $SYS["base_href"] . "/signon.php?&message=3&" . SID);
  5.   exit;
  6. }
  7.  
  8. $fromName = $HTTP_POST_VARS["fromName"];
  9. $fromEmail = $HTTP_POST_VARS["fromEmail"];
  10. $from = "From: " . $fromName . "<" . $fromEmail . ">";
  11. $subject = $HTTP_POST_VARS["subject"];
  12. $message = $HTTP_POST_VARS["message"];
  13. $phoollist = $HTTP_POST_VARS["phoollist"];
  14.  
  15. // Get list of players to email
  16. if($phoollist[0] == -1) {
  17.   // Get all players
  18.   $query = "SELECT fullname, email FROM $playertbl";
  19. } else {
  20.   // Get players participating in specific phools
  21.   $inPhools = "";
  22.   foreach($phoollist as $p) {
  23.     $inPhools .= "'$p', ";
  24.   }
  25.   $inPhools = substr($inPhools, 0, strlen($inPhools)-2);
  26.   $query = "SELECT DISTINCT P.fullname, P.email FROM $playertbl as P, $profiletbl as R WHERE P.playerID=R.playerID AND R.phoolID IN($inPhools)";
  27. }
  28.  
  29. if($players = &$conn->Execute($query)===FALSE) {
  30.   echo "<p>Could not complete selection of players:<br/>n" .
  31.     $conn->ErrorNo() . ": " . $conn->ErrorMsg() . "</p>n";
  32. } else {
  33.   $playerlist = $players->GetRows();
  34.   // Send email in batches of 50
  35.   $i=1;
  36.   echo "<p>"
  37.  foreach($playerlist as $p) {
  38.     $to = $p["fullname"] . "<" . $p["email"] . ">";
  39.     if(mail($to, $subject, $message, $from)) {
  40.       echo "Mail successfully sent to $to<br/>";
  41.     } else {
  42.       echo "Mail to $to unsuccessful<br/>";
  43.     }
  44.     if(!($i%50)) {
  45.       sleep(5)
  46.     }
  47.     $i++;
  48.   }
  49. };
  50. ?>

Reply With Quote
Old November 7th, 2002, 11:16 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,215 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Send a message via AIM to notepad
RE: parse error, unexpected T_FOREACH

sleep(5);
and yer last }; what's up with that home slice?

Reply With Quote
Old November 7th, 2002, 11:33 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,308 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 29
RE: parse error, unexpected T_FOREACH

Could you be more specific please? I'm very new to this. I'm modifying gpl code to suit my needs and I'm still trying to learn this stuff.. I added the ; to the sleep(5)and I got it to work kinda..

I have 6 people in the user list right now. It will send the first one then the rest fail with a server error.. do I need to slow it down somehow? I really appreciate all the help. Once again this is what I have now.

php Code:
Original - php Code
  1.  
  2. // Make sure we have a valid admin trying to access this file
  3. if($HTTP_SESSION_VARS["userID"]!=1) {
  4.   header("Location: " . $SYS["base_href"] . "/signon.php?&message=3&" . SID);
  5.   exit;
  6. }
  7.  
  8. $fromName = $HTTP_POST_VARS["fromName"];
  9. $fromEmail = $HTTP_POST_VARS["fromEmail"];
  10. $from = "From: " . $fromName . "<" . $fromEmail . ">";
  11. $subject = $HTTP_POST_VARS["subject"];
  12. $message = $HTTP_POST_VARS["message"];
  13. $phoollist = $HTTP_POST_VARS["phoollist"];
  14.  
  15. // Get list of players to email
  16. if($phoollist[0] == -1) {
  17.   // Get all players
  18.   $query = "SELECT fullname, email FROM $playertbl";
  19. } else {
  20.   // Get players participating in specific phools
  21.   $inPhools = "";
  22.   foreach($phoollist as $p) {
  23.     $inPhools .= "'$p', ";
  24.   }
  25.   $inPhools = substr($inPhools, 0, strlen($inPhools)-2);
  26.   $query = "SELECT DISTINCT P.fullname, P.email FROM $playertbl as P, $profiletbl as R WHERE P.playerID=R.playerID AND R.phoolID IN($inPhools)";
  27. }
  28.  
  29. if($players = &$conn->Execute($query)===FALSE) {
  30.   echo "<p>Could not complete selection of players:<br/>n" .
  31.     $conn->ErrorNo() . ": " . $conn->ErrorMsg() . "</p>n";
  32. } else {
  33.   $playerlist = $players->GetRows();
  34.   // Send email in batches of 50
  35.   $i=1;
  36.   echo "<p>";
  37.  foreach($playerlist as $p) {
  38.     $to = $p["fullname"] . "<" . $p["email"] . ">";
  39.     if(mail($to, $subject, $message, $from)) {
  40.       echo "Mail successfully sent to $to<br/>";
  41.     } else {
  42.       echo "Mail to $to unsuccessful<br/>";
  43.     }
  44.     if(!($i%50)) {
  45.       sleep(5);
  46.     }
  47.     $i++;
  48.   }
  49. };
  50. ?>

Reply With Quote
Old November 8th, 2002, 12:06 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,308 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 29
RE: parse error, unexpected T_FOREACH

Okay, looks like I've kinda figured out the prob. Now just need the fix... It will send to email addresses in my domain. Not anyone else.

Reply With Quote
Old November 8th, 2002, 02:06 AM
theermine theermine is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 35 theermine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
RE: parse error, unexpected T_FOREACH

I got it. For some reason I had to setup an SMTP server on my server to get it to work. Wouldn't go threw the ISP's.. oh well. Thanks a ton for the help.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > parse error, unexpected T_FOREACH


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap