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']."
";
}}
?>