保存到数据库时重复的whmcs api数据

时间:2019-05-09 08:18:49

标签: json api store whmcs

我正在弄清楚为什么每个数据中都有重复的数据。我的代码有什么问题吗?

   // Decode response
   $jsonData = json_decode($response,true);


    //store client data in db

    $clients = $jsonData['clients']['client'];

   foreach ($clients as $client) {      
   $firstname = $companyname = $email = '';
     foreach($client as $key => $value){
        switch($key){
           case 'firstname': $firstname = $value;
            break;
           case 'companyname': $companyname = $value;
            break;
           case 'email': $email = $value;
            break;
      }
    }
         if($firstname && $companyname && email){

      $sql = "INSERT INTO members ( `firstname`, `companyname`, `email`) 
      VALUES ('$firstname', '$companyname', '$email');";
      $query = $connect->query($sql);}


      if ($connect->query($sql) === TRUE) {
      echo "New record created successfully"."<br>";
       } else {
       echo "Error: " . $sql . "<br>" . $connect->error."<br>";
       }
      }

0 个答案:

没有答案