I just setup an SQL Server Database and initially I created a table called "Contacts" and added 2 records to it in MS Server Management Studio manually. Then I have the code below to test it to see if I can add a new record to it thru my website using JavaScript. I have run the code & get no errors, but it also does not add a new record to the Database? Can someone look at this and see if they see anything to why this will not work?
I have googled it, but have not been able to find any solution.
<!-- Open Database & add to it -->
<script type="text/javascript">
var db = openDatabase('C:/Program Files/Microsoft SQL
Server/MSSQL14.SQLEXPRESS/MSSQL/DATA/SFF-Database.mdf',
'1.0', 'Test DB', 8 * 1024 * 1024);
var msg;
db.transaction(function(tx) {
// tx.executeSql('CREATE TABLE IF NOT EXISTS CONTACTS (FirstName,
LastName, Address, City, State, PostalCode)');
tx.executeSql('INSERT INTO CONTACTS VALUES (3, "Jeff", "Williams",
"32568 Williams Street NW", "Portland", "OR",
"93445")');
msg = '<p>Log message created and row inserted.</p>';
document.querySelector('#status').innerHTML = msg;
})
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM CONTACTS', [], function(tx, results)
{
var len = results.rows.length,
i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++) {
msg = "<p><b>" + results.rows.item(i).FirstName + " " +
results.rows.item(i).LastName + " " +
results.rows.item(i).Address + " " +
results.rows.item(i).City + " " + results.rows.item(i).State +
" " + results.rows.item(i).PostalCode + "</b></p>";
document.querySelector('#status').innerHTML += msg;
}
}, null);
});
</script>
Why is it that there are no error's? yet it will not add a record into the Database.