Welcome Guest, Not a member yet? Register   Sign In
Insert array in database
#1

(This post was last modified: 09-03-2022, 08:27 AM by pippuccio76.)

HI i have this model :
Code:
protected $allowedFields = ['id','id_categoria_lavorazione','nome','codice','menu_linea_implantare','scala_colori','numero_dente','quantita_elementi','prezzo_vendita_da_file','gg_lavorativi','created_at','updated_at','deleted_at'];


scala_colori is type json in db

this is the $post variable from form:
Code:
Array ( [id_categoria_lavorazione] => 32 [nome] => test [codice] => DM4CCSX [menu_linea_implantare] => SI [scala_colori] => Array ( [0] => 37 [1] => 39 [2] => 19 [3] => 3 ) [numero_dente] => 10 [quantita_elementi] => 15 [prezzo_vendita_da_file] => 20 [gg_lavorativi] => 1 )

i simpli do 
this is my error : $descrizione_lavorazione_model->save($post);
Operand should contain 1 column(s)

How can i insert the array into json field ?

SOLVED:

Code:
            $post['scala_colori'] = json_encode($post['scala_colori']);


            $res=$descrizione_lavorazione_model->save($post);
Reply
#2

You should never put the $post or $get arrays into a database it's a security problem waiting to happen.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(09-04-2022, 12:46 AM)InsiteFX Wrote: You should never put the $post or $get arrays into a database it's a security problem waiting to happen.

Why?  However the insertion is on admin side .
Reply
#4

Because SQL code injection could be inserted into the $post or $get array and then executed.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(09-05-2022, 04:24 AM)InsiteFX Wrote: Because SQL code injection could be inserted into the $post or $get array and then executed.

Which is the correct way to insert array into json field of a db's table ?
Reply
#6

First check your $post or $get array to make sure it has the right data ( Never trust user input )

PHP How to INSERT a JSON object/array in a MySQLi Database
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(09-06-2022, 12:20 AM)InsiteFX Wrote: First check your $post or $get array to make sure it has the right data ( Never trust user input )

PHP How to INSERT a JSON object/array in a MySQLi Database

i check first with validate...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB