我有一些非常奇怪的东西,我的代码基本上工作正常,如果我这样做:
include_once ('includes/MailChimp.php');
use Drewm;
$con = mysql_connect("localhost","db_username","db_password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_database", $con);
$result = mysql_query("SELECT username, user_id, email FROM db_users");
while ($user = mysql_fetch_array($result))
{
echo $user['username'];
echo '<br>';
}
mysql_close($con);
打印所有用户名。没有错误。但随后我删除了2回显行,并将其替换为:
$result = $MailChimp->call('lists/subscribe', array(
'id' => 'x',
'email' => array('email'=>$user['email']),
'merge_vars' => array('USERNAME'=>$user['username'], 'UID'=>$user['user_id']),
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
));
它突然不工作了,给了我这个错误:
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, array given
它告诉我错误行是:
while ($user = mysql_fetch_array($result))
如果它在echo中工作得很好,那就没有意义了!
您正在覆盖变量$result
$result = mysql_query("SELECT username, user_id, email FROM db_users");
和
$result = $MailChimp->call('lists/subscribe', array...
change $result var for other