Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

338
Vistas
Express.js ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect integer value: '' for column 'id' at row 1

In my main.js file the string is "hello,0,,0,0" (empty at 2nd position if u read it in array) it need to be able to pass NULL into the database.
FYI: it will work if the 2nd position is a 0 and not empty
I am trying to split the string "," into var as shown below.

var Val = req.body.string.split(","); 
var one = Val[0];
var two = Val[1];
var three = Val[2];
var four = Val[3];
var five = Val[4];
let sqlquery = "INSERT INTO TESTING (one, two, three, four, five) VALUES (?,?,?,?,?)";

let newrecord = [one, two, three, four, five];  
db.query(sqlquery, newrecord, (err, result) => {
if (err) {
return console.error(err.message);
} else
res.send("Added in database");

and i got this error
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect integer value: '' for column 'three' at row 1

The table i created: CREATE TABLE TESTING (one VARCHAR(50), two BOOLEAN, three INT(4), four INT(4), five BOOLEAN ,PRIMARY KEY(name));
fields are all NULL
No auto increment in the table above, there is another table i created using the exact same way but with auto increment id but still throws the same error

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since you know that parameter three is a number, you could write

var three = Val[2] || null;

I assume you later execute a command like

db.query(sqlquery, [one, two, three, four, five]);

Then, if Val[2] = "0", you get three = "0", and this string value is accepted by the database for a numeric 0.

But Val[2] = "" is a falsy value, therefore you get three = null, and this is hopefully accepted by the database for a NULL value.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda