-2

I am trying to loop array from database in email.php but i am getting this error:

Parse error: syntax error, unexpected ';', expecting ')' in /home/xxx/public_html
/email.php on line 62 

This is the code in email.php:

$allowed_senders = Array(

  $query = "SELECT email FROM members";  // Line 62
  $result = mysql_query($query); 
  while ($row = mysql_fetch_assoc($result)) 
  { 
    $loop_email = $row['email'];
    echo "'".$loop_email."',";   
  }    

); 

I don't understand what went wrong. Any help?

richard
  • 1,456
  • 4
  • 15
  • 22

1 Answers1

3

Your syntax is way off:

  $allowed_senders = array();

  $query = "SELECT email FROM members";  // Line 62
  $result = mysql_query($query); 
  while ($row = mysql_fetch_assoc($result)) 
  { 
    $allowed_senders[] =  $row['email'];
  }   

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496