duanqian9593 2013-06-18 21:44
浏览 68
已采纳

我的php变量导致mailchimp api错误

I am pretty new at this so here is my franken code.

My goal is have the new person added to mysql update to my mailchimp list. I'm doing this a step at a time while I learn.

The mysql code will return the row that I want if i use "echo" The mailchimp api will update the list when manual enter the values into the code. However if I put them together I get an error says that a ',' was expected.

My guess is that it has to do with the [0] part of the variables $row[0]

Thanks for the help.

<?php
//mysql code

mysql_connect('localhost', '****', '****') or die( mysql_error() );
mysql_select_db('cla-constituents');



$result = mysql_query("SELECT per_FirstName, per_LastName, per_Email FROM person_per WHERE per_FriendDate > '2013-03-18'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);

//echo $row[0]; // first name
//echo $row[1]; // last name
//echo $row[2]; // email




/**
This Example shows how to run a Batch Subscribe on a List using the MCAPI.php 
class and do some basic error checking or handle the return values.
**/

require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey

$api = new MCAPI($apikey);
$listId = "****3";



$batch[] = array('EMAIL'=>$row[0], 'FNAME'=>$row[1]), 'LNAME'=>$row[2]);
$batch[] = array('EMAIL'=>'boss2.man@email.org', 'FNAME'=>'Me2', 'LNAME'=>'Chimp2');

$optin = False; //yes, send optin emails
$up_exist = true; // yes, update currently subscribed users
$replace_int = false; // no, add interest, don't replace

$vals = $api->listBatchSubscribe($listId,$batch,$optin, $up_exist, $replace_int);

if ($api->errorCode){
    echo "Batch Subscribe failed!
";
    echo "code:".$api->errorCode."
";
    echo "msg :".$api->errorMessage."
";
} else {
    echo "added:   ".$vals['add_count']."
";
    echo "updated: ".$vals['update_count']."
";
    echo "errors:  ".$vals['error_count']."
";
    foreach($vals['errors'] as $val){
        echo $val['email_address']. " failed
";
        echo "code:".$val['code']."
";
        echo "msg :".$val['message']."
";
    }}
?> 
  • 写回答

1条回答 默认 最新

  • douzhi7070 2013-06-18 21:54
    关注
    $batch[] = array('EMAIL'=>$row[0], 'FNAME'=>$row[1]), 'LNAME'=>$row[2]);
    

    Change to:

    $batch[] = array('EMAIL'=>$row[0], 'FNAME'=>$row[1], 'LNAME'=>$row[2]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办