How to insert Json data into mysql using php

0

I have a document with json format data that I want to insert into phdmyadmin DB, I am able to insert the first data into the table that is within "results", but I am not able to enter "catechisms_students_attributes" "education_sponsor_description".

Json Document:

 {
    results: [
    {
    catechist_description: "Albertina Dinis",
    class_year: "2017/2018",
    finalized: true,
    id: 33,
    is_for_adults: false,
    name: "catequese 2o",
    start_time: "23:00",
    week_day: "7",
    year: 2,
    catechisms_students_attributes: [
    {
    catechism_id: 33,
    created_at: "2017-10-19T15:47:49",
    deleted: false,
    education_sponsor_description: "José Paulo Almeida Bernardes",
    education_sponsor_id: 173486,
    entity_description: "Manuel Rocha",
    entity_id: 173502,
    id: 154,
    inscription_date: "2017-10-19",
    observations: null,
    transferred: false,
    updated_at: "2017-10-19T15:47:49"
    },
    {
    catechism_id: 33,
    created_at: "2017-11-04T11:04:45",
    deleted: false,
    education_sponsor_description: "Manuel Rocha",
    education_sponsor_id: 173502,
    entity_description: "teste",
    entity_id: 185503,
    id: 156,
    inscription_date: "2017-11-04",
    observations: null,
    transferred: false,
    updated_at: "2017-11-04T11:04:45"
    }
    ],
    }

The code I'm using:

    curl_close($ch3);
    $decode_catechisms = json_decode($response3, true);


    foreach ($decode_catechisms["results"] as $catechisms_object) {
        $id_catechisms = $catechisms_object['id'];
        $catechist_description = $catechisms_object['catechist_description'];
        $class_year = $catechisms_object['class_year'];
        $catechist_name = $catechisms_object['name'];
        $start_time = $catechisms_object['start_time'];
        $week_day = $catechisms_object['week_day'];
        $catechism_year = $catechisms_object['year'];
        $education_sponsor_description = $catechisms_object['catechisms_students_attributes']['education_sponsor_description'];


//insert into mysql table
        $sql = "INSERT INTO catechisms (id_catequese, catechist_description, class_year, name, start_time, week_day, year, education_sponsor_description)
    VALUES('$id_catechisms','$catechism_year', '$class_year', '$catechist_name','$start_time', '$week_day', '$catechism_year', '$education_sponsor_description')
    ON DUPLICATE KEY UPDATE
    id_catequese='$id_catechisms', catechist_description='$catechist_description', class_year='$class_year', name='$catechist_name',"
                . " start_time='$start_time', week_day='$week_day', year='$catechism_year', education_sponsor_description='$education_sponsor_description'";

The error you are giving me is "Notice: Undefined index: education_sponsor_description" Could they help me?

    
asked by anonymous 22.12.2017 / 23:28

0 answers