我正在尝试从email.php中的数据库循环数组,但我收到此错误:
Parse error: syntax error, unexpected ';', expecting ')' in /home/xxx/public_html
/email.php on line 62
这是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."',";
}
);
我不明白出了什么问题。有什么帮助吗?
答案 0 :(得分:3)
您的语法是方式关闭:
$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。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。