I have sqlite database with 4 columns
Name
Age
bloodGroup
lastdate
and 4 input fields and saving button as following:
<input type="text" name="" id="patientName">
<input type="number" name="" id="PatientAge">
<input type="text" name="" id="PatientBloodGroup">
<input type="date" name="" id="PatientLastDate">
<button id="savebtn"> Save </button>
and i used the following javascript code to take the input values and insert them into the columns of the database :
<script type="text/javascript">
document.getElementById('savebtn').addEventListener('click', saveFunction);
function saveFunction(){
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('./database_name');
var patientName = document.getElementById('patientName').value;
var patientAge = document.getElementById('patientAge').value;
var patinetBloodGroup = document.getElementById('patientBloodGroup').value;
var PatientLastDate = document.getElementById('patientLastDate').value;
db.run(`INSERT INTO info(Name, Age, bloodGroup, lastdate) VALUES(patientName, patientAge, patientBloodGroup, PatientLastDate), function(err) {
if (err) {
return console.log(err.message);
}
console.log(`A row has been inserted with rowid ${this.lastID}`);
});
db.close();
}
</script>
When the program is run it gives this error message :
SQLITE_ERROR: no such column: patientName.
infodoesn't have the columnNamein itpatientNamewhich clearly isn't what you want. Try something like the 'Insert Multiple Records' part on this page: w3schools.com/nodejs/nodejs_mysql_insert.asp (obviously, you only want one record.