【发布时间】:2020-08-31 21:56:08
【问题描述】:
好吧,我想我越来越接近解决这个问题了。现在我正在端口 3000 上运行如下脚本。
curl localhost:3000/register?name=bob\&width=13.970000\&time=0
curl localhost:3000/wheels?left=0.000000\&right=0.000000\&time=0 --cookie "USER=bob"
curl localhost:3000/echo?dist=9.220000\&time=10 --cookie "USER=bob"
curl localhost:3000/line?l1=1\&l2=1\&l3=1\&time=20 --cookie "USER=bob"
curl localhost:3000/other?ir=0\&time=30 --cookie "USER=bob"
curl localhost:3000/wheels?left=3.000000\&right=3.000000\&time=100 --cookie "USER=bob"
curl localhost:3000/echo?dist=9.220000\&time=110 --cookie "USER=bob"
curl localhost:3000/line?l1=1\&l2=1\&l3=1\&time=120 --cookie "USER=bob"
curl localhost:3000/other?ir=0\&time=130 --cookie "USER=bob"
curl localhost:3000/wheels?left=3.000000\&right=3.000000\&time=200 --cookie "USER=bob"
curl localhost:3000/echo?dist=9.220000\&time=210 --cookie "USER=bob"
curl localhost:3000/line?l1=1\&l2=1\&l3=1\&time=220 --cookie "USER=bob"
然后我使用 nodejs 和 express 将这些查询参数添加到数据库中。一切都在使用'/register',因为我可以在我的数据库中存储'user'和'width'的数据,但是当我尝试从'/wheels 更新相同的表'left1'和'right1'属性时' 那么我能做的最多就是将数据插入到一个全新的表中,其中名称和宽度都恢复为默认值。
最后,我要做的是让应用程序在汽车数据库中创建一个新的数据库条目,填写名称、宽度、left1、right1、时间、dist、l1、l2、l3、ir 数据行,然后在所有这些都填写完毕后在数据库中创建另一个条目......但我现在所能做的就是让它输入大量不同的数据集,这些数据集只有名称(bob)和宽度(14)属性填写..这是我的代码:
const express = require('express');
const session = require('express-session');
const mysql = require('mysql');
let app = express();
var pool = mysql.createPool( {
host: 'localhost',
user: 'root',
password: 'secret',
database: 'cars',
connectionLimit: 10,
multipleStatements : true
});
app.get('/register', function(req, res) {
pool.query("INSERT INTO cars (`name`, `width`, `time`) VALUES (?,?,?)", [req.query.name, req.query.width, req.query.time]);
});
app.get('/wheels', function (req, res) {
pool.query("UPDATE `cars` SET `left1`=?, `right1`=?",
[req.query.left, req.query.right]) });
app.listen(3000, function(req, res) {
console.log('Express JS ready for port 3000');
});
这是数据库的图片:phpMyAdmin database pic
知道我哪里可能出错了吗?有人告诉我也许可以尝试使用会话和 cookie,但我一直在网上查找诸如“cookie-parser”和“cookie-sessions”之类的东西,但我一直没有使用它们。我不知道如何使用它们对 mysql 数据库做任何事情,而且我在网上找不到任何与我试图用它做的事情相关的东西......太困惑了。任何帮助都会很棒!谢谢
【问题讨论】: