I’m developping a button with css and i used SQLite and jquery to build the OnClick event but the query didn’t work .After clicking the button with id =”gameLogin” i want to insert the value of the input field firstName in the table Contacts . After running the database and the table are created ,
any idea please? is There another solution ?
Thank you much
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SQL Storage</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="css/main.css" />
</head>
<body>
<br/><br/>
<div align="center">
<section id="gameIntro">
First name:<input type="text" id="firstName"/><br/>
<p><a id="gameLogin" class="button3 blue medium" href="game.html">Login</a>
</p>
</section>
</div>
</body>
<script>
var results = document.getElementById('results');
//var id = document.getElementById('id');
var firstName = document.getElementById('firstName');
var createStatement = "CREATE TABLE IF NOT EXISTS Contacts (firstName TEXT PRIMARY KEY )";
var selectAllStatement = "SELECT * FROM Contacts";
var insertStatement = "INSERT INTO Contacts (firstName) VALUES (?)";
var updateStatement = "UPDATE Contacts SET firstName = ?, WHERE firstName = ?";
var deleteStatement = "DELETE FROM Contacts WHERE firstName=?";
var dropStatement = "DROP TABLE Contacts";
var findStatement = "SELECT * FROM Contacts WHERE firstName=?";
var db = openDatabase("AddressBook", "1.0", "Address Book", 200000);
var dataset;
createTable();
$("#gameLogin").click( function(){
db.transaction( function(tx) {tx.executeSql(insertStatement,[firstName.value],onErrorLogIn,goplay); });
});
.......... .........
Also, with the jQuery library, things like
document.getElementByIdare completely unnecessary. It’s very obvious from the look of your code that you have a "grand idea" you wish to achieve, but you really need to read some documentation on how to use jQuery, and on how to make proper SQL calls with MVC.I’m going through the trouble of making a suggested reading list, I strongly recommend you check ALL of these links out.
W3 Schools JS (not the best guide, but if you can’t pass the test they have for JS you’re not quite ready for libraries)
jQuery Documentation
jQueryUI Documentation
Free PHP tutorials (this is the language to best make SQL calls from because it keeps the call "server" side which helps prevent hacking)
Codeigniter (A Great Opensource PHP Library)
Beginner Guide to MVC with Codeigniter (How to make a login, basically)
SQL Injection Wiki also See This (Will tell you why what you’re doing is so bad, or should at least give you a clue)
And finally, if you’re making an online game with js, I would suggest the following jQuery Plugin
GameQuery
And if you still insist on using SQL in javascript, read this