0

I have this code that loads a file called mailchimp-api and signs a user up to a newsletter:

<?php

if(isset($_POST['email'])){
    $email = $_POST['email'];

    include("mailchimp-api.php");

    $chimp = new MailChimp('XXXXXXXXXX-us7');
    echo "API registered";
    $chimp = $MailChimp->call('lists/subscribe', array(
        'id'                => 'XXXXXXXXX',
        'email'             => $email,
        'double_optin'      => false,
        'update_existing'   => true,
        'send_welcome'      => true,
    ));
    echo "values set";
    if( $result === false ) {
        $error = "There was an error signing you up! Please try again";
    }   
    elseif( isset($result->status) && $result->status == 'error' ) {
        // Error info: $result->status, $result->code, $result->name, $result->error
        $error = $result->error;

    }

}

?>

The code fails at the $chimp = $MailChimp->call line, as shown by the debug echos. Why is this? phpcurl is definitley installed!

2
Contributors
3
Replies
12
Views
3 Years
Discussion Span
Last Post by cereal
1

You're starting the class in $chimp, not in $MailChimp, so change this:

$chimp = $MailChimp->call('lists/subscribe'

To:

$result = $chimp->call('lists/subscribe'

Edited by cereal

0

Okay, fixed that! Thanks! Futher down the page I either echo out the error or success messages and I get Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/siteoctopus/Web/gag/newsletter-event.php on line 59

Line 59 is the final closing php tag

<?php
        if(isset($error)){
        ?>
        <span class="error"><?php echo $error;?></span>

        <?php    
        }
        ?>
        <?php
        if($success===true){
            echo "<span class='green'>Signed up!</span>";
        }
        ?>
0

Probably somewhere, one of the echos or of the variables is missing a ;, for example:

if(1 == 1)
{
    echo 'true'
}

The missing ; will generate the same error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.