HTML Formular Input in SQLite Datenbank speichern, (mit NodeJS) wie?
Hallo. Ich möchte den Input eines HTML-Formulars mit Hilfe von Node in eine SQLite Datenbank einfügen.
Mein index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello world!</title>
<script src="sqlite.js"></script>
</head>
<body>
<form action="/team_name_url/" method="post">
<label for="team_name">Enter name: </label>
<input id="team_name" type="text" name="name_field" value="Default name for team.">
<input type="submit" value="OK">
</form>
</body>
</html>
Mein sqlite.js:
const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('./sqlite.db');
let express = require('express');
let app = express();
const bodyParser= require('body-parser');
app.use(bodyParser.urlencoded({extended:true}));
app.post('/',(req,res)=>{
let placeName = req.body.PlaceName;
});
db.run(`INSERT INTO places (id, name, coords) VALUES(4, ${placeName}, '1234, 5678');`, function(err) {
if (err) {
return console.log(err.message);
}
console.log(`A row has been inserted with rowid ${this.lastID}`);
});
db.close();
SQL,
HTML,
programmieren,
JavaScript,
Datenbank,
SQLite,
node.js,
node