nodejsとmysqlを使用してデータベースにデータを挿入するためにこのコードを作成しましたが、それは機能し、データは挿入されましたが、ページはまだリロードされ、データベースに同じ値を複数回nodejsページが再ロードを停止していません
server.js
var express = require('express');
var app = express();
var server = require('http').createServer(app);
bodyParser = require('body-parser');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
database: 'chmult',
user: 'root',
password: '',
});
users = [];
connections = [];
app.get('/', function(req, res){
res.sendFile(__dirname + '/');
});
app.use(bodyParser.urlencoded({
extended: true
}));
/**bodyParser.json(options)
* Parses the text as JSON and exposes the resulting object on req.body.
*/
app.use(bodyParser.json());
connection.connect();
app.post("/", function (req, res) {
console.log(req.body.user.username)
connection.query("Insert into tesko (username) VALUES ('"+req.body.user.username+"')")
});
app.listen(3231);
console.log('Example app listening at port:3000');
htmlコード
<html>
<form method="post" action="">
<input type="text" name="user[username]">
<input type="submit" value="Submit">
</form>
</html>
ユーザー入力をSQLクエリーに盲目的に連結して、注入攻撃を求めています。 **これをしないでください** – mscdex