logging into the system with cordova

Currently, I am encountering an SQL processing error with the message "SQL: undefined" here. In this code block, my aim is to verify if the login form matches any entry in the database named 'student'. If a match is found, an alert popup displaying a welcome message should appear and the user should be directed to the next page. How can I resolve the issue within the code?

document.addEventListener("deviceready", onDeviceReady, false);

var db;

function onDeviceReady() {
    db = window.openDatabase("Database", "1.0", "Student", 2 * 1024 * 1024);
    db.transaction(createDB, errorCB, successCB);
}

function loginForm(){
    db.transaction(checkDB, errorCB);
    $.mobile.changePage("#page5",{reverse:false,transition:"slide"});
    return false;
}

function checkDB(tx){
    var _matric=$("[name='matric']").val();
    var _password=$("[name='password']").val();
    var sql ='select * from STUDENT where matric='+_matric+' and password='+_password+'';
    tx.executeSql(sql,[],successLoginDB,errorCB);
}

function successLoginDB(tx,results){
    var len = results.rows.length;
    var _name =$("[name='name']").val();
    if (len == 1) {alert("Welcome "+_name);}
}

Answer №1

Your current code is susceptible to potential security threats such as SQL Injection. To address this issue, consider utilizing args in your code:

function loginForm(){
   db.transaction(checkDB, errorCB);
   $.mobile.changePage("#page5",{reverse:false,transition:"slide"});
   return false;
}

function checkDB(tx){
   var matric=$("[name='matric']").val();
   var password=$("[name='password']").val();
   var sql ='select * from STUDENT where matric = ? and password = ?';
   tx.executeSql(sql,[matric, password],successLoginDB,errorCB);
}

function successLoginDB(tx,results){
   var len = results.rows.length;
   var name =$("[name='name']").val();
   if (len==1) {alert("Welcome "+name);}
}

In regards to the error mentioned, it appears that you may be attempting to use webSQL before cordova fully loads. A solution would be to ensure you wait for "DOM Ready" to read text inputs, and "deviceready" event to access WebSQL:

document.addEventListener("deviceready", onDeviceReady, false);

var onDeviceReady = function () {
    // Start here.
}

Please provide more information if needed.

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

What is the process for removing the binding of this jQuery element?

My online store on Shopify relies on Ajax calls for adding products to the cart and jQuery for front-end updates. Recently, I integrated infinite-ajax-scroll which caused some unexpected issues. After scrolling down to view products loaded by infinite-aja ...

Submitting data via AJAX using the method parameter

I have a specific ajax form that requires serialization and the manual setting of the _method for the data form. This is how I am currently handling it. $.ajax({ url: http://someposturl.com/object, type: 'POST', ...

Avoiding the hashtag symbol in a serialized string

I have a serialized string that I am sending to the server, structured like this: counter=1&Id=4&type=2332&amount=3232&gstIncluded=3232&paymentMethod=2&notes=2332#fdsf&docId=0&ref=3232&isEdit=true The issue I am encoun ...

The splash screen is failing to appear on the display

I'm working on an Android Application and I'm having trouble displaying a Splash Screen for 6 seconds. Instead of the Splash Screen showing up when I open the app, the screen that was previously my start-page appears. Below is the code snippet f ...

Totally clueless when it comes to JSON

After diving into tutorials on JSON, the structure and syntax are finally clicking for me. However, I'm currently working on a project that requires a GET, and it seems like JSON could help with this. I've come across comparisons of JSON and AJA ...

Encountered an issue with mapping data from a controller to a view in Angular.js

Currently, my application consists of only three small parts: a service that makes an http call to a .json file, a controller that receives data from the service and sends it to a view. Everything was working fine when I hard coded the data in my service. ...

Internet Explorer failing to trigger Ajax requests

I'm encountering an issue with my script on my webpage - it works perfectly in Chrome, but Internet Explorer is not entering the success{} function of Ajax. It does go into the Complete{} function without any problems. I attempted to pass the data var ...

Implementing Oauth in Angular and Node

I am facing challenges with implementing oauth in Angular. When I directly enter the link into the browser http://localhost:8080/auth/twitter I am able to successfully connect using oauth and receive a response. However, when I try to achieve the same in ...

Navigating to my own posts within Nuxt: A guide

Having trouble with internal links in my template, as they are not directing to the correct URLs. <nuxt-link :to="blog.url" >{{ blog.title }} by {{ blog.author }}</nuxt-link > In my data, I have the foll ...

Troubleshooting problems with VueJS routing

Currently, I am expanding my skills with VueJS by working on a user login system. My main goal is to prevent a logged-in user from accessing the login or register pages and instead redirect them to the dashboard page. To achieve this, I am utilizing stor ...

Customizing line charts with D3.js and AngularJS for ultimate visual impact

Working on a project involving the creation of a line chart using D3.js library and AngularJS within an Ionic framework. I am looking to customize the color of data points based on the Y-axis values. For example, if the value falls between 0-30, I want t ...

"Exploring the versatility of NextJS with dynamic route parameters

Can NextJS be configured to handle dynamic routes that match both /country and /country/city, while excluding matches like /country/city/whatever_content_here? The goal is to display the same content for either of the specified routes, regardless of whethe ...

What is the best way to extract data from the ajax.done() function?

My question revolves around the function shown below: $.ajax({ url: "../../getposts.php" }).done(function(posts) { var postsjson = $.parseJSON(posts); }); I am wondering how I can access the variable postsjson outside of the .done() function sco ...

Adjusting the height of an element in AngularJS based on its width dynamically

I am working on a table that is generated using ng-repeat, and I want to ensure that each td in the tbody is square. Since all the tds have an equal width, I only need to adjust the first one. However, the size of the table and td will change when the wind ...

Is there a way to make my red div switch its background color from red to green when I press the swap button?

How can I make the red div change its background color to toggle between red and green when I click on the swap button in the following code? $(document).ready(onReady); var numberOfClicks = 0; function onReady() { console.log('inside on ready ...

Is there a problem with the configuration of my Express parsing setup?

Server const express = require("express"); const app = express(); app.listen(4000, () => console.log("listening at 4000")); app.use(express.static("public")); app.use(express.json({limit: "1mb"})); //POST meth ...

How to efficiently group all keys in lodash using groupBy

I'm currently exploring ways to efficiently aggregate all items within a collection. Specifically, I am interested in identifying the most effective method using Lodash to group this set of objects by each of their keys (in depth), assuming that the ...

ERROR: Expo TaskManager Notifications [TypeError: Attempting to call an undefined function (near '...Notifications.presentLocalNotificationAsync...')]

I'm currently trying to figure out how to send notifications whenever a task is triggered, but I keep encountering an error that I can't seem to fix. Here's the error message: TaskManager: Task "background-fetch" failed:, [TypeError: unde ...

Issue with React rendering numbers without displaying div

In my user interface, I am attempting to display each box with a 1-second delay (Box1 after 1 second, Box2 after another 1 second, and so on). https://i.sstatic.net/FdTkY.png However, instead of the desired result, I am seeing something different: https ...

notifying progress indicator bar

I attempted to include the progress bar in the notification, but encountered a problem where the system would not respond for a few seconds and the progress bar would get stuck at the beginning once it started. It's important to note that even though ...