Jump to content

Validate if record exists in a database websql


Aud11
 Share

Recommended Posts

Hi i am trying to retrieve a user from a database based on the username and password entered and then if the user exists i then go to the next page,i am using one function and global variables..what is giving me a problem is that i want to use the form data before executing the validate function..please help

 

var db = openDatabase('AudreyTeracore', '1.0', 'Company Registration DB', 2 * 1024 * 1024);
var nameContent = new Array(); // now it's global!
var passwordsArray = new Array();
var nameT=document.getElementById("username").value;
var passwordT=document.getElementById("password").value;
db.transaction(function(tr){
tr.executeSql("select UserName,Password From UserLogin Where UserName='"+nameT+"' And Password ='"+passwordT+"' ", [],
function(tx, result)
{
for (var i = 0; i < result.rows.length; ++i)
{
var row = result.rows.item(i);
var name = row.UserName;
var pass = row.Password;
nameContent.push(name);
passwordsArray.push(pass);
}
});
});
function checkValid() {
for (var i = 0; i < nameContent.length; ++i)
{
if(nameContent!="" && passwordsArray!=""){
alert("Sucessfully logged in")
document.getElementById('form1').action = "EditUser.html";
break;
}
else
{
alert("Please enter valid username and password");
}
}
}
Link to comment
Share on other sites

If you're trying to use WebSQL, you realize that the database only exists on the user's computer, right? Every user that goes to your site has a different database, saved on their computer, and the only records in that database are records that they have created themselves. When web sites have a registration and login system that database is stored on the server, not the user's computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...