Utilize a line break within a MySQL UPDATE statement

After using JSON.stringify, my stringified variable looks like this:

{"ops":[{"insert":"drfsdfgg sdfg sdg \ns\ndfg\ndf\nsg\nsdfg\n"}]}

However, when I perform an UPDATE, the data in the MySQL database appears as follows:

{"ops":[{"insert":"drfsdfgg sdfg sdg 
s
dfg
df
sg
sdfg
"}]}

I want to keep all the "\n" characters preserved as they are in the INSERT operation! (yes, INSERT works)

This is the SQL query being used:

connection.query("UPDATE products SET description ='" + req.body.description + "' WHERE id = " + req.body.id, function (error, results, fields) {
if (!!error) {
console.log('error');
} else {
// console.log(results);
res.json();
};
});

Answer №1

After much searching, I've finally cracked the code - it all comes down to mastering SQL syntax. A big shoutout to myself and my amazing brain power for figuring this out!

connection.query("UPDATE products SET description = ? WHERE id = " + req.body.id, [req.body.description], function (error, results, fields) {
if (!!error) {
console.log('error');
} else {
// console.log(results);
res.json();
};
});

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

Deep Dive into TypeScript String Literal Types

Trying to find a solution for implementing TSDocs with a string literal type declaration in TypeScript. For instance: type InputType = /** Comment should also appear for num1 */ 'num1' | /** Would like the TSDoc to be visible for num2 as well ...

Calculating and displaying the output on an HTML page: A step-by-step guide

Within my HTML, I have two values stored in Session Storage: "Money" and "Time". These values are based on what the user inputted on a previous page. For example, if someone entered that they need to pay $100 in 2 days. My goal is to generate a list that ...

Dominant Editing through ASP.Net Roles

Looking for guidance on how to effectively use knockout with asp.net membership roles in MVC 4. My goal is to incorporate an editable grid on the page based on whether the user is an administrator or a 'registered user'. I want to ensure that use ...

Using Typescript: How to access a variable beyond the scope of a loop

After creating an array, I need to access the elements outside of the loop. I am aware that they are not in the scope and using 'this.' before them does not grant access. colIdx = colIdx + this.columns.findIndex(c => c.editable); this.focusIn ...

At what point does the promise's then function transition to being either fulfilled or rejected?

When dealing with promises in JavaScript, the then() method returns a promise that can be in one of three states: pending, fulfilled, or rejected. You can create a promise using the resolved and rejected methods to indicate when it should be fulfilled or r ...

I am unable to get the radio button checked in Angular 2

I have set up a form with two radio buttons for gender selection, and I want to ensure that the previously selected option is displayed as checked. Here's the code snippet I've added in my template: <div class="form-group"> <label& ...

Toggle the visibility of an element with a single button click

Below is a snippet of my sample code: SAMPLE HTML CODE: <ul> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <l ...

Using wildcard in Angular app for MQTT observation

My curiosity lies in MQTT wildcards and how they function, specifically while utilizing the mosqitto broker. Let's say I have around 1-2k topics. In my frontend, I am observing them with a single-level wildcard using ngx-mqtt. Will there be a separat ...

Guide to transforming a vertical tabbed content panel into a responsive collapsible using media queries and jQuery

I am in the process of creating a new content navigation design that incorporates vertically stacked tabs to toggle hidden panels adjacent to the tabs. Unfortunately, this layout seems to encounter issues at narrower screen widths. Check out my work on Fi ...

Displaying array data without the need for a loop in Vue.js and Axios

I want to display data in my Vue.js 3 app without using a loop. Here is the response from my Axios API: In My Axios Api I got reponse: [{id: 2, name: "sub_title", value: "The Best Developer Team", created_at: null, updated_at: null},… ...

Explore numerous databases using mongoosastic

Currently in my Node.js application, I am utilizing Mongoosastic to fetch data from ElasticSearch : Article.search({ "match_all": {} }, function (err, results) { console.log(results.hits.hits); Post.search({ "match_all": {} }, function (err, r ...

In Node.js, fast-xml-parse is only returning a single object instead of an array

Currently, I am working on implementing tracking functionality using a specific service that provides responses in XML format. For parsing the XML response, I have opted to utilize the fast-xml-parser package. However, I have encountered an issue: Everyth ...

Comparing time values between MySQL and the current time using PHP

Hello there! I am facing a challenge with the end_time stored in my database. When I retrieve it using $row['end_time'], I get a string in the format '2013:10:20 10:10:21'. I'm looking to convert this string into a time format so t ...

Some components react to history.push() with react-router-dom while others simply don't seem to respond

As the title states, I am using React-router-dom in my App.js file with a Router containing multiple Routes and a Switch. I have been successful in manipulating history and navigating my app using useHistory and history.push() in smaller components. Howev ...

A guide on incorporating the input type 'date' for date columns in jqGrid

When using jqGrid for inline editing, a date column is defined in the colmodel with accompanying JavaScript code. However, it can be cumbersome to maintain and produces an unattractive result. In instances where the browser supports it, how can one utiliz ...

The SQL function COUNT() fails to execute properly in MySQL databases

SELECT person.id, person.name, COUNT(DISTINCT fruit.apple) AS "Red Apple", fruit.* FROM (SELECT * FROM tree ORDER BY color DESC) AS fruit INNER JOIN person ON fruit.id = person.id WHERE person.name ...

Converting a React.Component into a pure function: A step-by-step guide

Eslint is recommending that I use a pure function instead of a react component. 

I have eslint set up with the airbnb config.

 Error: Component should be written as a pure function - react/prefer-stateless-function class App extends Component ...

Performing an XMLHttpRequest in the same JSP file using Javascript

I am working on a JSP file that contains three dropdown boxes labeled "countries", "regions", and "cities". My goal is to populate the regions based on the selected country, and the cities based on the selected region. I have managed to achieve this using ...

Utilize Vue's prop system to pass objects between components

Can you help with passing objects as props in Vue? It seems like a simple task, but I'm having some trouble. In my .vue file, I have the following code: <template> <div id="scatter"></div> </template> <script&g ...

Output the contents of a nested object

After setting up a variable containing music library data... var library = { tracks: { t01: { id: "t01", name: "Code Monkey", artist: "Jonathan Coulton", album: "Thing a Week Three" }, t02: { id: " ...