'Using UPDATE through a component, not working
// UPDATE
app.put("/update", (req, res) => {
const id = req.body.id;
const slack_id = req.body.slack_id;
const absent = req.body.absent;
db.query( "UPDATE developers SET slack_id = ?, absent = ? WHERE id = ?",[slack_id, absent, id],
(err, result) => {
if (err) {
console.log(err);
} else {
res.send(result);
}
}
);
});
Backend Update
const handleSubmit = (e, id) => {
e.preventDefault();
updateDeveloper(id);
}
const updateDeveloper = (id) => {
Axios.put(`${url}/update`, { slack_id: props.slackId, absent: props.absent, id: id }).then(
(response) => {
return (
{
id: id,
slack_id: props.slackId,
absent: props.absent,
name: props.name,
selected: props.selected
}
)
})
}
I'm trying to have an UPDATE function in React js, I use Props for this, everything works well so far but the only thing which is not working is the update itself. I've been working at this for hours and I cant figure out what the problem is precisely, On the website it works fine but when I press the update button nothing happens. It does catch the necessary ID but that's all, values dont change when I insert them.
if someone can help a hand?
return (
<div className='formDeveloper'>
<div>
<h3>Slack ID:<br /> {props.slackId} </h3>
<h3>Absent:<br /> {props.absent} </h3>
<h3>Name:<br />{props.name} </h3>
<h3>Selected:<br /> {props.selected} </h3>
</div>
<div>
{/* Button Update Developer */}
<form onSubmit={(e) => handleSubmit(e, props.id)}>
<input type="text" placeholder="Change Slack ID"/><br></br>
<input type="number" max="1" placeholder="Change Absence" /><br></br>
<button type="submit">Update</button>
</form>
{/* Button Delete Developer */}
<button onClick={() => { deleteDeveloper(props.id) }}>Delete</button><br></br>
</div>
</div>
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
