我使用 nodeJS 和 MySql 创建了一个宠物店 Web 应用程序。我能够成功在数据中插入宠物信息,但无法使用 pet_id 删除宠物。我收到以下错误
[代码:'ER_TRUNCATED_WRONG_VALUE',errno:1292,sqlMessage:“截断了不正确的双值:'pa04'”,sqlState:'22007',索引:0,sql:“从宠物中删除,其中pet_id = ='pa04'”]
pet_id
。
但是当我将 pet_id 指定为整数时,即;5 没有任何反应,甚至没有出现错误。我尝试将 Ajax 代码放入我的 ejs 中,但失败了。请帮我。提前致谢 :)
const { count } = require('console');
var express = require('express');
var mysql=require('mysql');
const { createConnection } = require('net');
var app = express();
var bodyparser=require('body-parser');
app.set("view engine","ejs");
app.use(bodyparser.urlencoded({extended:true}));
app.use(express.static(__dirname +"/public"))
var connection=mysql.createConnection({
host:'localhost',
user:'root',
database:'mini_project',
password:'password'
});
app.get("/animals", function(req, res){
var q="select animals.pet_id,pet_category,breed,weight,age,height,fur,cost from animals join pets on animals.pet_id= pets.pet_id";
connection.query(q,function(err,results){
if(err) throw err;
res.render("dogs_home",{data:results});
});
});
app.get("/birds", function(req, res){
var q="select birds.pet_id,type,noise,cost from birds join pets on birds.pet_id= pets.pet_id";
connection.query(q,function(err,results){
if(err) throw err;
res.render("birds_home",{data:results});
});
});
app.get("/",function(req,res){
res.render("home");
});
app.get("/accessories", function(req, res){
var q="select * from pet_products";
connection.query(q,function(err,results){
if(err) throw err;
res.render("accessories",{data:results});
});
});
app.get("/sales", function(req, res){
var q="select * from sales_details";
connection.query(q,function(err,results){
if(err) throw err;
res.render("sales",{data:results});
});
});
慕丝7291255
慕神8447489
相关分类