0

I'm trying to create a RESTFul API for using Nodejs with MYSQL to create a CRUD web app. GET and POST seem to be working fine, but when I try to implement an update with PUT, I get a 404 not found error.

If I use a POST, and have the update sql statement it works fine, but using PUT doesnt seem to work. This code gives a 404 in the browser ... exact same code, put using router.post instead of put works?

router.put('/edit/:id', function(request, response, next){
        var personId = request.body.personId;
        var firstName = request.body.firstName;
        var lastName = request.body.lastName;
            
        var query = `UPDATE person SET firstName = "${firstName}", lastName = "${lastName}" WHERE personId = "${personId }"`;
        
        database.query(query, function(error, data){
        if(error)
        {
            throw error;
            console.log(error);
        }   
        else
        {
            response.redirect("/mypage");
        }

    }); 

    ```
Eireash
  • 99
  • 1
  • 1
  • 8

0 Answers0