title: MailChimp group options select in php
body: <p>I tried to find the answer for the last 5 hours but I finally caved in and am reaching out for help.</p>
  
  <p>Basically, this code worked great until I needed to select a group option. I'm not sure if I'm creating my interests array properly, I may have to use 'merge_vars' but really would like some guidance before I spend another 5 hours blindly walking into walls.</p>
  
  <p>Note for my group name I've been using the entire string "group[3117]"</p>
  
  <p>Action.php     </p>
  
  <pre><code>&lt;?php
  session_start();
  if(isset($_POST['submit'])){
  $fname = $_POST['fname'];
  $lname = $_POST['lname'];
  $email = $_POST['email'];
  $interest = $_POST['group[3117]'];
  
  if(!empty($email) &amp;&amp; !filter_var($email, FILTER_VALIDATE_EMAIL) === false){
      // MailChimp API credentials
      $apiKey = '+ insert api key here +';
      $listID = 'insert list id';
      $interest = 'insert group name'; // YOUR INTEREST/GROUP ID
  
      // MailChimp API URL
      $memberID = md5(strtolower($email));
      $dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
      $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID;
  
      // member information
      $json = json_encode([
          'email_address' =&gt; $email,
          'status'        =&gt; 'subscribed',
          'merge_fields'  =&gt; [
              'FNAME'     =&gt; $fname,
              'LNAME'     =&gt; $lname
          ],
              'interests'        =&gt; array(
          $interest =&gt; true
          ),
      ]);
  
      // send a HTTP POST request with curl
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
      curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
      $result = curl_exec($ch);
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);
  
      // store the status message based on response code
      if ($httpCode == 200) {
          $_SESSION['msg'] = '&lt;p style="color: #34A853"&gt;You have successfully subscribed to CodexWorld.&lt;/p&gt;';
      } else {
          switch ($httpCode) {
              case 214:
                  $msg = 'You are already subscribed.';
                  break;
              default:
                  $msg = 'Some problem occurred, please try again.';
                  break;
          }
          $_SESSION['msg'] = '&lt;p style="color: #EA4335"&gt;'.$msg.'&lt;/p&gt;';
      }
  }else{
      $_SESSION['msg'] = '&lt;p style="color: #EA4335"&gt;Please enter valid email address.&lt;/p&gt;';
  }
  }
  // redirect to homepage
  header('location:index.php');  
  </code></pre>
  
  <p>Index.php</p>
  
  <pre><code>&lt;?php session_start(); // place it on the top of the script ?&gt;
  &lt;?php
  $statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
  unset($_SESSION['msg']);
  echo $statusMsg;
  ?&gt;
  &lt;form method="post" action="action.php"&gt;
  &lt;p&gt;&lt;label&gt;First Name: &lt;/label&gt;&lt;input type="text" name="fname" /&gt;&lt;/p&gt;
  &lt;p&gt;&lt;label&gt;Last Name: &lt;/label&gt;&lt;input type="text" name="lname" /&gt;&lt;/p&gt;
  &lt;p&gt;&lt;label&gt;Email: &lt;/label&gt;&lt;input type="text" name="email" /&gt;&lt;/p&gt;
  &lt;p&gt;&lt;select name="group[3117]" class="REQ_CSS" id="mce-group[3117]"&gt;
  &lt;option value=""&gt;&lt;/option&gt;
  &lt;option value="1"&gt;Los Angeles&lt;/option&gt;
  &lt;option value="2"&gt;Seattle&lt;/option&gt;
  &lt;option value="4"&gt;Portland&lt;/option&gt; &lt;/p&gt;
  &lt;p&gt;&lt;input type="submit" name="submit" value="SUBSCRIBE"/&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>