Save data to MySQL - json_encode











up vote
-2
down vote

favorite












I have a problem with transferring data to the database.



So yes - I created a controller in CodeIgniter 3, which is to send data to the database.



Before sending, the data is checked using JWT.



My code PHP looks like this:



public function create()
{
$token = $this->input->post('token');
$this->jwt->decode($token, config_item('encryption_key'));

$payload = $this->input->post('payload');
unset($payload['login']);
unset($payload['email']);
unset($payload['role']);

$note = $this->input->post('note');
$note = json_encode($note);

$data = $payload;

$data['note'] = $note;
$this->notes_model->create($data);
}


AngularJS:



 $scope.noteCreated = function( note ){
$http({
method: 'POST', url: 'api/admin/notes/create/', data: {'note' : note, token: checkToken.raw(), payload: checkToken.payload()} }
).then(function (){
$scope.success = true;


$timeout( function(){
$scope.success = false;
$scope.note = {};

console.log(note);


}, 2000);

},function (error){
console.log('Blad we wczytywaniu danych');
});
}


The data it receives after sending it is in this form:



enter image description here



And they should look like this:



enter image description here



Problem: How to transfer data to get to your columns?










share|improve this question






















  • Why are you using json_encode, when what you want apparently isn’t actually JSON? You probably want to fill $data['note'], $data['id_domain_rel'] etc. with individual values.
    – misorude
    2 hours ago










  • Exactly, the data $data['note'], $data['id_domain_rel'] is transmitted on the form - but they save as you see, and I would like them to go to the appropriate columns
    – danko12
    2 hours ago










  • You problem is $data['note'] = $note; You encode data to json and store into db. Simple pass array into model->create()
    – S. Denis
    2 hours ago















up vote
-2
down vote

favorite












I have a problem with transferring data to the database.



So yes - I created a controller in CodeIgniter 3, which is to send data to the database.



Before sending, the data is checked using JWT.



My code PHP looks like this:



public function create()
{
$token = $this->input->post('token');
$this->jwt->decode($token, config_item('encryption_key'));

$payload = $this->input->post('payload');
unset($payload['login']);
unset($payload['email']);
unset($payload['role']);

$note = $this->input->post('note');
$note = json_encode($note);

$data = $payload;

$data['note'] = $note;
$this->notes_model->create($data);
}


AngularJS:



 $scope.noteCreated = function( note ){
$http({
method: 'POST', url: 'api/admin/notes/create/', data: {'note' : note, token: checkToken.raw(), payload: checkToken.payload()} }
).then(function (){
$scope.success = true;


$timeout( function(){
$scope.success = false;
$scope.note = {};

console.log(note);


}, 2000);

},function (error){
console.log('Blad we wczytywaniu danych');
});
}


The data it receives after sending it is in this form:



enter image description here



And they should look like this:



enter image description here



Problem: How to transfer data to get to your columns?










share|improve this question






















  • Why are you using json_encode, when what you want apparently isn’t actually JSON? You probably want to fill $data['note'], $data['id_domain_rel'] etc. with individual values.
    – misorude
    2 hours ago










  • Exactly, the data $data['note'], $data['id_domain_rel'] is transmitted on the form - but they save as you see, and I would like them to go to the appropriate columns
    – danko12
    2 hours ago










  • You problem is $data['note'] = $note; You encode data to json and store into db. Simple pass array into model->create()
    – S. Denis
    2 hours ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I have a problem with transferring data to the database.



So yes - I created a controller in CodeIgniter 3, which is to send data to the database.



Before sending, the data is checked using JWT.



My code PHP looks like this:



public function create()
{
$token = $this->input->post('token');
$this->jwt->decode($token, config_item('encryption_key'));

$payload = $this->input->post('payload');
unset($payload['login']);
unset($payload['email']);
unset($payload['role']);

$note = $this->input->post('note');
$note = json_encode($note);

$data = $payload;

$data['note'] = $note;
$this->notes_model->create($data);
}


AngularJS:



 $scope.noteCreated = function( note ){
$http({
method: 'POST', url: 'api/admin/notes/create/', data: {'note' : note, token: checkToken.raw(), payload: checkToken.payload()} }
).then(function (){
$scope.success = true;


$timeout( function(){
$scope.success = false;
$scope.note = {};

console.log(note);


}, 2000);

},function (error){
console.log('Blad we wczytywaniu danych');
});
}


The data it receives after sending it is in this form:



enter image description here



And they should look like this:



enter image description here



Problem: How to transfer data to get to your columns?










share|improve this question













I have a problem with transferring data to the database.



So yes - I created a controller in CodeIgniter 3, which is to send data to the database.



Before sending, the data is checked using JWT.



My code PHP looks like this:



public function create()
{
$token = $this->input->post('token');
$this->jwt->decode($token, config_item('encryption_key'));

$payload = $this->input->post('payload');
unset($payload['login']);
unset($payload['email']);
unset($payload['role']);

$note = $this->input->post('note');
$note = json_encode($note);

$data = $payload;

$data['note'] = $note;
$this->notes_model->create($data);
}


AngularJS:



 $scope.noteCreated = function( note ){
$http({
method: 'POST', url: 'api/admin/notes/create/', data: {'note' : note, token: checkToken.raw(), payload: checkToken.payload()} }
).then(function (){
$scope.success = true;


$timeout( function(){
$scope.success = false;
$scope.note = {};

console.log(note);


}, 2000);

},function (error){
console.log('Blad we wczytywaniu danych');
});
}


The data it receives after sending it is in this form:



enter image description here



And they should look like this:



enter image description here



Problem: How to transfer data to get to your columns?







php angularjs codeigniter-3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









danko12

457




457












  • Why are you using json_encode, when what you want apparently isn’t actually JSON? You probably want to fill $data['note'], $data['id_domain_rel'] etc. with individual values.
    – misorude
    2 hours ago










  • Exactly, the data $data['note'], $data['id_domain_rel'] is transmitted on the form - but they save as you see, and I would like them to go to the appropriate columns
    – danko12
    2 hours ago










  • You problem is $data['note'] = $note; You encode data to json and store into db. Simple pass array into model->create()
    – S. Denis
    2 hours ago


















  • Why are you using json_encode, when what you want apparently isn’t actually JSON? You probably want to fill $data['note'], $data['id_domain_rel'] etc. with individual values.
    – misorude
    2 hours ago










  • Exactly, the data $data['note'], $data['id_domain_rel'] is transmitted on the form - but they save as you see, and I would like them to go to the appropriate columns
    – danko12
    2 hours ago










  • You problem is $data['note'] = $note; You encode data to json and store into db. Simple pass array into model->create()
    – S. Denis
    2 hours ago
















Why are you using json_encode, when what you want apparently isn’t actually JSON? You probably want to fill $data['note'], $data['id_domain_rel'] etc. with individual values.
– misorude
2 hours ago




Why are you using json_encode, when what you want apparently isn’t actually JSON? You probably want to fill $data['note'], $data['id_domain_rel'] etc. with individual values.
– misorude
2 hours ago












Exactly, the data $data['note'], $data['id_domain_rel'] is transmitted on the form - but they save as you see, and I would like them to go to the appropriate columns
– danko12
2 hours ago




Exactly, the data $data['note'], $data['id_domain_rel'] is transmitted on the form - but they save as you see, and I would like them to go to the appropriate columns
– danko12
2 hours ago












You problem is $data['note'] = $note; You encode data to json and store into db. Simple pass array into model->create()
– S. Denis
2 hours ago




You problem is $data['note'] = $note; You encode data to json and store into db. Simple pass array into model->create()
– S. Denis
2 hours ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













To save data into different columns, you have to make array like this:



$data['noted'] = $note['noted'];
$data['id_domain_rel'] = $note['id_domain_rel'];


now you can pass $data .



Please dont use json_encode.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370641%2fsave-data-to-mysql-json-encode%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    To save data into different columns, you have to make array like this:



    $data['noted'] = $note['noted'];
    $data['id_domain_rel'] = $note['id_domain_rel'];


    now you can pass $data .



    Please dont use json_encode.






    share|improve this answer

























      up vote
      0
      down vote













      To save data into different columns, you have to make array like this:



      $data['noted'] = $note['noted'];
      $data['id_domain_rel'] = $note['id_domain_rel'];


      now you can pass $data .



      Please dont use json_encode.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        To save data into different columns, you have to make array like this:



        $data['noted'] = $note['noted'];
        $data['id_domain_rel'] = $note['id_domain_rel'];


        now you can pass $data .



        Please dont use json_encode.






        share|improve this answer












        To save data into different columns, you have to make array like this:



        $data['noted'] = $note['noted'];
        $data['id_domain_rel'] = $note['id_domain_rel'];


        now you can pass $data .



        Please dont use json_encode.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Madhuri Patel

        409213




        409213






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370641%2fsave-data-to-mysql-json-encode%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Volksrepublik China

            How to test boost logger output in unit testing?

            Write to the output between two pipeline