mercredi 3 juin 2020

React not fetching data from mysql

I build a react app using nodejs and mysql. I want to update an entry from react but the following code doesn't working and I can't understan what is the problem. Any suggestions are much appreciated.

// from index.js

script.get('/updatepost/:id', (req, res) => {
    let sql = `UPDATE posts SET name = '${req.body.name}', school='${req.body.school}' WHERE id = ${req.params.id}`;
    let query = connection.query(sql, (err, result) => {
        if(err) {
            return err;  
        }
        console.log(result);
        res.send('Post updated...');
    })
});

//from react component

axios(`http://localhost:4000/updatepost/${userId}`, {
method: 'PATCH',
data: qs.stringify(data);
})



Aucun commentaire:

Enregistrer un commentaire