php - SQL request error because of an integer -
i have problem sql request (insert). i'm using handsontable save data in database. here grid user enters data. row "numéro pe" numeric field in database it's not required field, can empty !!
as have lot of grid one, made generic function insert data. create string data :
foreach($ligne $key => $elt) { $values .= '\''.$elt.'\','; if ($key == ($cptidessai-1)) { $values .= '\''.$id_essai.'\','; } }
and call function string in parameters , works perfectly.
but problem : row "numéro pe" numeric, request doesn't work.
here warning on firebug :
query failed: erreur: invalid syntax integer : « » line 2: ... essai2','test essai2_trait1','test essai2_bloc1','','','');
pb request:
insert public.parcelle_elementaire(id_traitement,bloc,id_pe,id_essai,code_traitement,id_bloc,numero_pe,taille_pe,commentaires) values('test essai2_trait1','1','test essai2_trait1_1','test essai2','test essai2_trait1','test essai2_bloc1','','','');
can me resolve please ?
edit :
so it's hard explain problem i'm going give more informations more details step step.
so :
1- user enters data in grid.
2- when submits, send content of grid ajax , insert values in database.
2.1- make first string row headers , string :
id_traitement,bloc,id_pe,id_essai,code_traitement ,id_bloc,numero_pe,taille_pe,commentaires
2.2- make second string data user wrote , string :
'test essai2_trait1','1','test essai2_trait1_1','test essai2','test essai2_trait1' ,'test essai2_bloc1','','',''
so, data empty, , it's completly normal.
3- send 2 string in function insert values
insert($champsbase,$values,$tablebdd); //here call function update($champsdb,$idupdate,$tablebdd,$idtable) //here function { $conn_string = "host=localhost port=5432 dbname=test_postgre user=postgres password='1234'"; $dbconn = pg_connect($conn_string); $sql = "update public.".$tablebdd." set ".$champsdb." '.$idtable.'='".$idupdate."'"; $res = pg_query($sql) or die("pb avec la requete: $sql");
}
4- variables (the 2 strings made) have request (which working)
insert public.parcelle_elementaire(id_traitement,bloc,id_pe,id_essai,code_traitement ,id_bloc,numero_pe,taille_pe,commentaires) values('test essai2_trait1','1','test essai2_trait1_1','test essai2','test essai2_trait1' ,'test essai2_bloc1','','','');
but request doesn't work because value linked "numero pe" numeric in database , send quotes ''
. value isn't required field. that's why don't know how do.
Comments
Post a Comment