SQL request error because of an integer

I have a problem with a sql request (insert). I’m using handsontable to save data in my database. So here is my grid where the user enters the data.
The row “Numéro pe” is an numeric field in the database but it’s not a required field, so it can be empty !! enter image description here

As I have a lot of grid like this one, I made a generic function which insert the data. So I create a string with the data like this :

foreach($ligne as $key => $elt)
{       
    $values .= '''.$elt.'',';


    if ($key == ($cptIdEssai-1))
    {
        $values .= '''.$id_essai.'',';
    }
}

And I call the function with this string in parameters and it works perfectly.

But my problem is : as my row “numéro pe” is a numeric, the request doesn’t work.

Here is the warning on firebug :

Query failed: ERREUR: invalid syntax with the integer : « »
LINE 2: … ESSAI2′,’TEST ESSAI2_TRAIT1′,’TEST ESSAI2_BLOC1′,”,”,”);

Pb with the request:

INSERT INTO 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 someone help me to resolve that please ?


Source: mysql

Leave a Reply