Database record fails to update

The code is executing without any errors, but the database table does not get updated

id and status are being retrieved from an HTML form

router.get('/update_todo/:todo_id',async function(req,res){
const id = req.body.todo_id;
const status = req.body.complete;
const queryString = "UPDATE todos SET completed = ? WHERE todo_id = ?";
con.query(queryString,[id,status],function(err,rows,fields){
    if(err)
    {
        console.log(err.message)
    }
    else
    {
        console.log("Update successful")
         
    }
})

})

The output appears as:

fieldCount  0
affectedRows    0
insertId    0
serverStatus    2
warningCount    0
message "(Rows matched: 0  Changed: 0  Warnings: 0)"
protocol41  true
changedRows 0

Answer №1

To modify the array sequence, switch the position of the array members from [id,status] to [status, id]

Additonally, as pointed out by Robert Kawecki, make sure your request is a POST request in order to retrieve the status value from the body.

router.post('/update_todo/:todo_id',async function(req,res){
    const id = req.params.todo_id;
    const status = req.body.complete;
    const queryString = "UPDATE todos SET completed = ? WHERE todo_id = ?";
    con.query(queryString,[status, id],function(err,rows,fields){
        if(err)
        {
            console.log(err.message)
        }
        else
        {
            console.log("Update successful")
         
        }
    });

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The collaboration of Node.js and React.js on a single server

Separate ports are used for Node and React, but API requests from the React app can be proxied to the Node URL. I have opted not to implement server-side rendering for React in order to serve the React app. Instead, I build the React app each time there i ...

Guide to deploying an AngularJS application on Heroku with Node.js without the use of yeoman

I am currently working on deploying a Hello World build using AngularJS in Heroku with Node.js, incorporating multiple views (partials). Initially, I successfully deployed a basic Hello World without utilizing ngRoute, which means without partials. Howeve ...

Error in Node.js: Packet sequence mismatch. Received: 0, Expected: 244

For the past 10 days, I've been grappling with this issue. Despite trying everything I could find on Google, I still haven't found a suitable solution. After initiating "npm start" on the server at night, I woke up to an error in the morning. th ...

Encountering an issue with Angular 5.2 application build on VSTS build server: Running into "CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory" error

Out of nowhere, the builds began failing with the following error : 2019-01-03T12:57:22.2223175Z EXEC : FATAL error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error MSB3073: The command "node node_modules/webpack/bin/w ...

What is the best way to establish a connection between two services in a Docker-compose setup so that they are able to communicate with each

I'm new to Docker and facing challenges in connecting two separate services using docker-compose. I need to be able to write to a database and read from it. Additionally, each container should be able to ping the other one. When I run docker exec -ti ...

I am encountering an issue with the react-use-cart package as it requires the string "id" while my API data only provides the object "_id". Is there a way to convert or manipulate the

Seeking assistance with integrating an item into a cart system. The function requires the id of the item, but my item only generates the _id and not simply the id. Grateful for any insights from those with expertise in this area. Thank you in advance! htt ...

Mongoose: Perform a bulk upsert operation, ensuring that only records meeting specific criteria are updated

I am in the process of developing an inventory management system for a website that is currently under construction. The inventory data of users is retrieved from a Web API and then transformed to better suit the requirements of my web application. My goa ...

Guide on Utilizing Forever Alongside Express for Continuous Operation of a NodeJS Server

Currently, I have an Express NodeJS server that I personally initiate via the terminal with npm start in the root directory of my project. To ensure consistent uptime, I opted to install the Forever package globally. However, when I try to run Forever on m ...

Building an NPM package similar to [name]/[second_name]? The name must consist of URL-friendly characters. How should we include the "[second_name]" in this package?

Can anyone help me understand how to append a package name with something after the slash in NPM? For instance, when creating a package, you typically use: npm init and when specifying the name, it gives an error if I include a "/" character as it restri ...

Working with TypeScript to set a value for an object's field

I have two objects of the same model: interface Project { _id?: string title: string description: string goal: string tasks?: Task[] createdAt?: Date updatedAt?: Date } The first object contains all fields from the interface, while the secon ...

Returning a 404 Error stating "Invalid request to /api/users/register."

Encountering an issue with proxy connection - unable to determine the root cause despite verifying all routes. Not able to successfully register the user and store data in MongoDB. Seeking suggestions for resolution. Thank you. Attempting to send user reg ...

Failed to bind MariaDB with Node.js using Docker Compose

I have successfully set up a MariaDB/NodeJS environment using docker-compose: version: '3' services: app: image: node:alpine volumes: - ./:/app working_dir: /app environment: NODE_ENV: dev ...

Experiencing a lack of email delivery when using the "adminCreateUser" feature in AWS Cognito

My current challenge involves utilizing the `adminCreateUser` function to create a new User, but I am encountering an issue where the temporary password is not being sent to my email address. var RegisterUser = exports.RegisterUser = function (data) { v ...

Use the npm command key to globally install a package

My attempt to globally install gulp on OS X has led to a perplexing discovery. Initially, I used the command: npm install -g glup This resulted in an error message: npm ERR! Darwin 14.4.0 npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "glup" n ...

What is the systematic approach to verify if the npm packages listed in the package.json file are actually being utilized in the

Is there a way to verify that all modules listed in the package.json file of a node project are actively being used within the project itself? Consider a situation where multiple individuals are contributing to the project, continuously adding new npm pac ...

Automated algorithm inspecting a variety of hyperlinks

Recently, I've developed an innovative anti-invite feature for my bot. However, there seems to be a minor glitch where the bot fails to remove any links sent within the enabled guild when the command is triggered. This issue specifically occurs in ver ...

An undefined value is encountered in a function within Node.js

To test this code snippet in node.js v6.0.0: x = 3; var foo = { x:1, bar: { x: 2, baz: function() { console.log(this.x); } } }; foo.bar.baz(); var a = foo.bar.baz; a(); An error is thrown: 2 TypeError: Cannot read property &apos ...

MEAN Stack Development: Why does the timestamp stored by Node.js appear different from the time on my laptop in Dev Mode?

Can someone assist me with properly displaying the correct datetime stamp? For example, the time on my laptop is: 02-Oct-2021 11:14am (this is in India) The time stored by Node and displayed in Angular is 2021-10-02T05:44:09.022Z, which is 06:30 behind m ...

Node.js: Leveraging Express to Compare URL Parameters and Handle Delete Requests with Array Values

Having some issues with the Express routes I set up for an array of objects and CRUD operations. Everything works smoothly except for the "Delete" operation. I am trying to delete an object by matching its URL parameter ID with the value of its key. Howev ...

Perform an update followed by a removal操作

I've been facing a persistent issue that has been troubling me for quite some time now. The setup involves a database in MariaDB (using WAMP) and an API in ExpressJS. Within the database, there are two tables: "menu" and "item," with a foreign key rel ...