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:
And they should look like this:
Problem: How to transfer data to get to your columns?
php angularjs codeigniter-3
add a comment |
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:
And they should look like this:
Problem: How to transfer data to get to your columns?
php angularjs codeigniter-3
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 intomodel->create()
– S. Denis
2 hours ago
add a comment |
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:
And they should look like this:
Problem: How to transfer data to get to your columns?
php angularjs codeigniter-3
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:
And they should look like this:
Problem: How to transfer data to get to your columns?
php angularjs codeigniter-3
php angularjs codeigniter-3
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 intomodel->create()
– S. Denis
2 hours ago
add a comment |
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 intomodel->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
add a comment |
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
.
add a comment |
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered 2 hours ago
Madhuri Patel
409213
409213
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 intomodel->create()
– S. Denis
2 hours ago