Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!