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!

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

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

To:

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.