HTML Web SQL Insert
HTML Web SQL Insert
In the following example, we will create a table ('myTeam') under the database ('studentsDB') and insert some data.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="insertData()">Insert Data</button>
<script>
var db = openDatabase('studentsDB', '1.0', 'Test DB', 2 * 1024 * 1024);
function insertData(){
db.transaction(function (tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS myTeam (id unique, name)');
tx.executeSql('INSERT INTO myTeam (id, name) VALUES (1, "Brendan")');
tx.executeSql('INSERT INTO myTeam (id, name) VALUES (2, "Harley")');
});
}
</script>
</body>
</html>
Insert with Callback
The following example will execute the callback function after inserting each data into the table.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="insertData()">Create DataBase</button>
<script>
var db = openDatabase('studentsDB', '1.0', 'Test DB', 2 * 1024 * 1024);
function insertData(){
// Insert Operation
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS myGroup (id unique, name)');
tx.executeSql('INSERT INTO myGroup (id, name) VALUES(?,?)', [1, "Abraham"],function(transaction,result){
console.log("inserted successfully 1");
});
tx.executeSql('INSERT INTO myGroup (id, name) VALUES(?,?)', [2, "Michael"],function(transaction,result){
console.log("inserted successfully 2");
});
});
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in HTML.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.