There seems to be a mysql error with a syntax issue causing an ER_PARSE_ERROR with errno 106

Encountered a Syntax error:

You have an error in your SQL syntax, please refer to the manual corresponding to your 
MySQL server version for the correct syntax to use near :data at line 1.
errno: 1064
SqlState: '42000'

This is The code used for database insertion:

function addCategory(category){
    var execution = q.defer();
    var query = 'INSERT INTO categories SET :data';
    console.log(query);
    connection.query(query,{data:category}, function(err, res){
        if(err){
            execution.reject(err);
            console.log(err);
            return;
        }
        execution.resolve(res);
    });
    return execution.promise;
}

This function expects a category as a JSON object. Interestingly, this function worked previously and was implemented similarly to the one causing the error.

Any insights on how to resolve this issue?

Answer №1

It appears that the query you are attempting to execute is invalid. Please refer to the INSERT syntax documentation for guidance. Typically, an INSERT query will resemble the format shown below:

INSERT INTO table_name (column1, column2) VALUES(value1, value2);

In your specific case, it is recommended to modify your query as follows:

var query = 'INSERT INTO categories (category) VALUES(:data)';

(Replace category with the name of your actual column)

Answer №2

#handling SQL queries in Express

#using PUT request for updating data
#data= req.body

 
pool.query("INSERT INTO product set ?", data, (error, results, fields) => {
            if (error) {return callBack(error);}
            return callBack(null, results);
        });


#sample data to be inserted
{
  "id": "4",
  "name": "tested1",
  "description": "cool",
  "final_rating": "3",
  "price": "4",
  "image_loc": "c"
}

#############################################

#using DELETE request

#data to delete
{
  "id":"1"
}

pool.query("delete from product where id=?", data, (error, results, fields) => {
        if (error) {return callBack(error);}
        return callBack(null, results);
    });

#data = req.body.id

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

Submit button in React form not activating the onSubmit method

Having an issue with a login form code where the submit handler is not being triggered when pressing the Submit button. Any idea what could be causing this? The loginHandler function does not seem to trigger, but the handleInputChange function works fine. ...

Creating a controller API in Express and Mongoose to send multiple "FIND" requests in a single query - a step-by-step guide

I have a single API to fetch data from the database. I am aiming to execute multiple "FIND" queries on mongoose, merge all the responses, and return the combined result. The technology stack includes Nodejs, Express for API development, and Mongoose for in ...

Specific Character Count in Regular Expressions

THIS IS DISTINCT FROM THE REFERENCED QUESTION because I have extensively researched and tested various solutions before resorting to posting this inquiry. I am in need of a validation for inputs that adhere to the following criteria: The first character ...

Struggling with parsing JSON strings into PHP arrays

I'm looking to transmit a JSON string using JavaScript and later convert it into an array using a PHP encoding function. After successfully converting the string in JavaScript and transmitting it via Ajax to a PHP page, I am encountering difficulties ...

Is there a way to decrease the jQuery UI file size?

Hey everyone! I recently downloaded a search box suggestion from this link. However, I noticed that the .js file at is quite large at 426kb. Does anyone know of a way to reduce the code within the file or have any simpler coding suggestions for creating ...

Implementing AngularJS table filters on user click

As a newcomer to angularjs, I am attempting to implement a filter on click. The user will select a source and destination, then click on the filter button. The table should display results based on the input. Upon page load, the table should already contai ...

What are some ways I can utilize Babel in standalone mode to convert an HTML import into a variable declaration?

I am trying to utilize the Babel plugin babel-plugin-transform-html-import-to-string to dynamically transform my code in the browser client. However, the babel-plugin-transform-html-import-to-string is designed to run on node with file libraries, which are ...

Tips for properly invoking a function from one component to another component

After browsing through a few questions on the topic of parent/child elements, I have come across a particular node tree that looks like this: IndexPage -> Modals -> ClientDetails (it's modal component) -> Header My goal is to ...

Working with SQLite Database on Android with Inserted Data Row

Developing an application with pre-inserted rows in the database for user convenience has been a bit challenging. Despite researching various solutions on similar topics, I still find myself grappling with some confusion. Currently, my DB class houses all ...

Is this the correct method for implementing AJAX syntax?

I am currently working on implementing AJAX functionality to verify the existence of a user in my database. At the moment, I am focusing on checking for duplicates based on their first and last name. Below is the code snippet that I have been working on: ...

Tips for assigning identifiers to dynamically generated elements in KnockOutJS

Is it possible to assign unique IDs to dynamically created elements in KnockOutJS? I have two spans - one for the button and another for a small icon in the corner of the button. There are a total of 6 elements like this, but they do not have unique IDs. ...

Creating a dynamic side navigation menu that adjusts to different screen sizes

I have been working on a project's webpage that was initially created by another Software Engineer. After he left, I continued to work on the webpage. The issue I encountered is that he preferred a side menu over a navbar using the left-panel and righ ...

Obtain the location information upon the loading of the webpage

I am currently in the process of developing a website using HTML, CSS, and JavaScript. My goal is to automatically retrieve the user's location when the page loads, without requiring them to click a button. I would greatly appreciate any assistance wi ...

How can I ensure that remote_form_for adds new code in addition to existing code rather than replacing it in RoR?

I'm currently utilizing remote_form_for within Ruby on Rails to generate a form that will inject some HTML into the current page upon submission. However, my goal is to allow users to utilize this pop-up for inserting HTML multiple times, as opposed t ...

Changing the disabled textfield colour in Material-UI

I am looking to enhance the visibility of disabled text in a textfield by making it darker than the current light color: https://i.sstatic.net/Iw6Dp.png I have attempted to achieve this using the following code snippet: import { withStyles } from ' ...

Different outcome when passing parameter in MySql

I am currently working on an ASP.NET Core website where I am fetching products from a database using the following command: using (MySqlCommand cmd = new MySqlCommand("SELECT ROBAID, KATBR, NAZIV, SLIKA FROM ROBA WHERE PODGRUPA ...

Invoke a separate function from the ajax() success callback

My code includes a function that arranges JSON data into HTML using DoT.js, defined within $(document).ready(): $(document).ready(function() { function arrangeResults(jsonObject, templateFunc) { $(jsonObject).each(function(i, item) { ...

Update the state of a button in an HTML header file

I am in the process of building a simple website, but it's starting to feel cluttered. One factor contributing to this clutter is that I have a separate header for each page since I don't have a script to dynamically change button states when hov ...

Switching jQuery toggle effects to Angular framework

My current jQuery animations for toggling the sidebar are as follows: $('.sa-fixedNav_toggle').click(function () { $('.sa-fixedNav_positon').toggleClass('sa-fixedNav_size-grow') $('.pa-content_layout' ...

Apollo GraphQL has initiated the detection of a new subscription

My approach involves utilizing graphql-ws for subscribing to GraphQL events. I rely on the Observable interface to listen to these events. Although I can use the error callback to identify when a subscription fails to start, it is challenging to determine ...