Challenges with adding the current date into a WebSQL database using JavaScript in WebSQL

Can anyone help me figure out why the data is not being inserted into WebSQL when using the current date and time for INSERT and SELECT statements? Here's the code I'm currently using:

SETUP..
myDb.transaction(function(tr) {
        tr.executeSql('CREATE TABLE IF NOT EXISTS stInfo (keyNum INTEGER NOT NULL PRIMARY KEY, timestamp varchar(255) );');         
});

INSERTING DATA
function insert() {
 var timeStamp = getCurrentDate();  // returns in format YYYY-MM-DD HH:MM
myDb.transaction(function(tr) {
          tr.executeSql("INSERT INTO stInfo('keyNum','timestamp') values(215424," + timeStamp + ");");              
 });
}

Answer №1

Even though this is an old post, I will provide an answer. The simplest way to achieve this would be:

tr.executeSql('INSERT INTO stInfo (keyNum, timestamp) VALUES (?,?)',["215424", timestamp]);

Additionally, it's important to pay attention to your usage of double and single quotes.

Answer №2

Enclose the timestamp in single quotes:

tr.executeSql("INSERT INTO stInfo('keyNum','timestamp') values(346578, '" + timeStamp + "')");

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

Encountering the "TypeError: Unable to access property 'indexOf' of undefined" error while utilizing the ipfs-api

During my development work with the ipfs-api, I ran into an issue where adding an image file to the ipfs node was not functioning properly. Upon further investigation into the error details, it appears that the protocol is being treated as undefined in the ...

Ways to adjust the size or customize the appearance of a particular text in an option

I needed to adjust the font size of specific text within an option tag in my code snippet below. <select> <?php foreach($dataholder as $key=>$value): ?> <option value='<?php echo $value; ?>' ><?php echo ...

Implementing Typescript for managing state in React components

Currently, I have a state set up like this: const [newInvoice, setInvoice] = useState<InvoiceType | null>(invoice) The structure of my InvoiceType is as follows: customer_email: string customer_name: string description: string due_date: stri ...

Achieving the equivalent of php crypt() in NODE.JS

Can anyone assist with converting PHP to JavaScript (Node.js)? $key = crypt($key, $salt); I am currently in the process of rewriting a PHP script using Node.js, and I have encountered an issue with generating hash signatures similar to the ones created b ...

Issue: Module 'ansi-styles' not found when using AngularJS and Yeoman generator

Previously my code was functioning perfectly, but now it seems to have suddenly stopped working. Attempting yo angular:route api resulted in the following error message: Error: Cannot find module 'ansi-styles' at Function.Module._resolveFilen ...

Working with repeated fields in Google protobuf in JavaScript

Consider this scenario: you have a google protobuf message called Customer with a repeated field as shown below. message Customer { repeated int32 items = 1; } What is the procedure for setting the repeated items field in javascript? ...

What is the best way to loop through this object and send it to the client using ejs?

{ surveyCode:654321, q1:{ question:'What is your age?', option1:{ type:'number', placeholder:'Enter your age', header:'' } }, q2:{ q ...

Access JSON value using jQuery by key

Creating a JSON structure that contains information about attendees: { "attendees": [ { "datum": "Tue, 11 Apr 2017 00:00:00 GMT", "name": " Muylaert-Geleir", "prename": "Alexander" }, { "datum": "Wed, 12 Apr 2017 ...

Ajax data is not successfully reaching the designated URL when posted

My task involves sending data to a PHP site that contains code to be executed when the ID #mR-RateableFramePicture is clicked on the first page. This is achieved through an AJAX request: $('#mR-RateableFramePicture').dblclick(function() { ...

Technique for seamlessly moving between subpages and main page while scrolling to a specific id

I'm struggling with coding and thought I'd reach out for help here. Can anyone provide a solution to my problem? Issue - I have a navigation link on my main page that scrolls to an ID using jQuery. It works fine on the main page, but not on any ...

AngularJs input field with a dynamic ng-model for real-time data binding

Currently facing an issue with my static template on the render page. <form name="AddArticle" ng-submit="addArticle()" class="form add-article"> <input type="text" value="first" init-from-form ng-model="article.text[0]" /> <input typ ...

Leveraging AngularJS html5mode in conjunction with express.js

Client-side: when("/page/:id", { templateUrl: "partials/note-tpl.html", controller : "AppPageController" }); $locationProvider.html5Mode( true ); Html: <a ng-href="/page/{{Page._id}}">{{Page.name}}</a> Server-side: app.use("/pag ...

Internet Explorer freezing when running selenium executeScript

Hey everyone, I've spent the past couple of days scouring the internet trying to find a solution to my modal dialog problem. There's a wealth of helpful information out there and everything works perfectly fine except for Internet Explorer. Speci ...

Error: Unable to access the 'questionText' property as it is undefined

I encountered an error message stating that my "questionText" could not be read or is not defined. The issue seems to arise in the first code block where I use "questionText", while the intention is to drag it in the second code block. Is there a mistake ...

issue with for loop in jquery ajax not processing complete response data

I have a total of 9 columns in my table, namely choosen_emails_1, choosen_emails_2, choosen_emails_3, booking_address, booking_number, booking_message, booking_date, request_date & user_email The for loop is programmed to iterate and display all colum ...

Verify whether a certain key exists within the gun.js file

Suppose I need to verify whether a specific entry exists in the database before adding it. I attempted the following: gun.get('demograph').once((data, key) => { console.log("realtime updates 1:", data); }); However, I only receive ...

Searching for a pattern and replacing it with a specific value using JavaScript

I need to find all occurrences of an unknown string within a larger string that is enclosed in brackets. For example, the string may look like: '[bla] asf bla qwr bla' where bla is the unknown string I need to locate. Is it possible to achieve th ...

A stored procedure for Oracle to insert the current date and time into a date column

I have a function that I am currently using. TO_DATE(TO_CHAR (SYSDATE, 'YYYY-MON-DD HH24:MI:SS'),'yyyy/mm/dd hh24:mi:ss') Everything works perfectly when I update data using a simple query like:-- set modified_on= TO_DATE(TO_CHAR (SY ...

Update the link to a KML file used by Google Maps when a button is clicked

On the initial page load, I want to showcase an 8 Day Average KML file on Google Maps. However, users should have the option to click on the "1 Day" and "3 Day" buttons to switch the reference in Google Maps from the "8 Day" file. The aim is to design a s ...

What is the process of defining a route for a JSON response in an Express application?

I've been following an Angular tutorial on handling form submissions with promises, which I found here. My server is running on Node and I'm using Express to manage routes. However, when I submit the form and reach the line var $promise = $http. ...