我正在弄清楚为什么每个数据中都有重复的数据。我的代码有什么问题吗?
// 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>";
}
}