I want to insert json array data in mysql table. I have written this code.
if (mysqli_connect_errno()){
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
if(isset($_GET['doctorJson'])){
$json = $_GET['doctorJson'];
$array = json_decode($json, true);
foreach($array as $item){
$result = mysqli_query($con, "INSERT IGNORE INTO doctor_visit_track (id, doctor_name, doctor_email, date, time) VALUES
('".$item['id']."', '".$item['doctorName']."', '".$item['doctorEmail']."', '".$item['date']."', '".$item['time']."')");
}
if($result){
$response["message"] = "Success";
echo json_encode($response);
} else{
$response["message"] = "Failure";
echo json_encode($response);
}
}
mysqli_close($con);
Above code is working fine when I am using xampp. But when I have uploaded this code to server then same code is giving warning " Invalid argument supplied for foreach()" and not inserting in table. But using in xampp, code is working fine and inserting data successfully. Somebody help me..