Click here to Skip to main content
16,017,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making this SQL database using HTML5 the code is here
<!DOCTYPE HTML>
<html>
<head>
<script>
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
var msg;
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")');
tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');
msg = '

Log message created and row inserted.

';
document.querySelector('#status').innerHTML = msg;
});

db.transaction(function (tx) {
tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "

Found rows: " + len + "

";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "

" + results.rows.item(i).log + "

";
document.querySelector('#status').innerHTML += msg;
}
}, null);
});
</script>
</head>
<body>
Status Message

</body>
</html>



This codes adds the information in enter to my databse
tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")');
tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');


But instead of this, i want my user to enter their information in a textbox which then saves to my database

Please help
Thanks
Posted

1 solution

1. Never use Database Commands on the front-end (that is HTML, even if it is HTML5).

2. You should use a good back-end such ASP.Net or PHP.

3. In case you don't have/(care about) the aforementioned, use "input" tags in the body so there are controls the user can write the text into. Al input tags should be enclosed in
a "form" tag also.

4. Your script should be enclosed into a fuction, cause when it is not within a function it
just runs when the page loads (which is not what you want).

5. The button you use should call the function in which you enclosed your commands.


To achieve all of the aforementioned google "html controls", "html form tag", "javascript function", "button command".

This would be too much work to answer in a single solution buddy but I've given you a clue. it's up to you to gather all necessary knowledge.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900