I am new to app developing and I chose phonegap to create one. I have find difficulties to create an SQLite Database, in order to get data from a form which purpose is to register the users. I followed the instruction in the phonegap docs and also I checked for similar posts online and in stackoverflow but i can't find what's wrong. When i run it doesn't give me any alerts about the database and keeps returning me back on the my first page. Below is the code.
<script type="text/javascript">
document.addEventListener("deviceready" , OnDeviceReady , false);
function OnDeviceReady(){
var database = window.openDatabase("PuzzledDB","1.0","Puzzled",20000);
database.transaction(populateDB,errorDB,successDB);
}
function populateDB(tx){
tx.executeSql("CREATE TABLE IF NOT EXISTS Users (Username text, Password text, Email text, Role text)");
}
function errorDB(tx,error){
alert("Error processing SQL: "+err.code);
}
function successDB(){
alert("success!");
}
function Users(){
var username1 = document.getElementById("username").value;
var password1 = document.getElementById("password").value;
var email1 = document.getElementById("email").value;
var role1 = document.getElementById("role").value;
var database = window.openDatabase("PuzzledDB","1.0","Puzzled",20000);
database.transaction(function(tx){
NewUser(tx,username1,password1,email1,role1);},ErrorRegistration,SuccessRegistration);
}
}
function NewUser(tx,username1,password1,email1,role1){
tx.executeSql("INSERT INTO TABLE Users (Username,Password,Email,Role) VALUES ("+ username1 +",'"+ password1 +"','"+ email1 +"','"+ role1 +"')");
}
function ErrorRegistration(tx,error){
alert("Error processing SQL: "+err.code);
}
function SuccessRegistration(){
alert("success!");
});
}
</script>
<div data-role="page" id="pagefour" data-theme="c">
<div class="header" id="header" data-role="header">
<h3>Δημιουργια Λογαριασμου</h3>
</div>
<div id="wrapper">
<form>
<div data-role="main" class="ui-content" style="color:white">
<div class="username" data-role="ui-field-contain">
<label class="ui-hidden-accessible"> Όνομα Χρήστη </label>
<input type="text" id="username" name="username" value="" placeholder="Όνομα Χρήστη">
</div>
<div class="password" data-role="ui-field-contain">
<label class="ui-hidden-accessible"> Κωδικός </label>
<input type="password" id="password" name="password" value="" placeholder="Κωδικός">
</div>
<div class="email" data-role="ui-field-contain">
<label class="ui-hidden-accessible"> Email </label>
<input type="email" id="email" name="email" value="" placeholder="Email">
</div>
<div class="role" data-role="ui-field-contain">
<label class="ui-hidden-accessible"> Ρόλος </label>
<input type="text" id="role" name="role" value="" placeholder="Ρόλος">
</div>
<div class="register" data-role="ui-field-contain">
<input id="register" value="Υποβολη" type="submit" name="Register" onclick="Users();">
</div>
</div>
</form>
</div>
</div>
Thanks in advance for any help!!
Aucun commentaire:
Enregistrer un commentaire