Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Axios Post inside loop with changing variable REACT

I have an array of labels for form inputs named changing_variable, which are dependent on what a user selects from a drop down menu, so these are unknown.

I need to be able to let the property of the Axios.post method, equal to the variable in order to input the correct data into my database. Any examples I see online have properties like:

name: this.name
age: this.age 

However this cannot work for me since I cannot hard code the values since they change depending on the user input, and also there is over a hundred for each user input.

If anyone can help me pass this changing variable to my backend. Thanks

My current code :

var i;
var changing_variable;
for(i=1; i<arr.length; i++)
  {

    changing_variable = inputValues[i].text
  Axios.post(URL, changing_variable)
    .then(res => {
    console.log(res);
    console.log(res.data);
    console.log(changing_variable)
  })
  }
};

EDIT Node.js code

app.post('/create', (req,res) => {

const test_variable= req.body.changing_variable;


db.query("INSERT INTO iptable (test_variable) VALUES(?)",

[test_variable], (err,result) =>{

    if(err){
        console.log(err)
    }else {
        res.send("Values Inserted")
    }
}
)
});

Terminal error message code: 'ER_BAD_NULL_ERROR', errno: 1048, sqlMessage: "Column 'test_variable' cannot be null", sqlState: '23000', index: 0, sql: 'INSERT INTO iptable (test_variable) VALUES(NULL)'

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda