Я использую Node JS с Express JS, чтобы получить входные данные в форме и вставить эти входные данные в таблицу с именем "signup", используя Mysql, но когда я нажимаю кнопку отправки, "Cannot POST" "отображается на локальном хосте. Кто-нибудь может указать на ошибку, которую я делаю?
Мой HTML Код
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Registration Form</title>
<link href = "styles.css" rel = "stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Merriweather|Montserrat|Sacramento&display=swap" rel="stylesheet">
</head>
<body style="color: #40514E; font-size: 20px; font-family: 'Merriweather', serif; background-color: #EAF6F6;">
<h2 style="font-family: 'Sacramento', cursive; font-size: 4rem; text-align: center;">Sign Up</h2>
<form method = "post" enctype = "multipart/form-data" >
<div class = "container" styles="max-width: 1350px; width: 100%; margin: 50px; height: auto; display: block;">
<div class = "form_group" style="padding: 10px; display: block;">
<label style="float: left; padding-right: 50px; line-height: 10%; display: block; width: 208px;">First Name:</label>
<input type = "text" name = "FirstName" value = "" required/>
</div>
<div class = "form_group" style="padding: 10px; display: block;">
<label style="float: left; padding-right: 50px; line-height: 10%; display: block; width: 208px;">Middle Name:</label>
<input type = "text" name = "MiddleName" value = "" required />
</div>
<div class = "form_group" style="padding: 10px; display: block;">
<label style="float: left; padding-right: 50px; line-height: 10%; display: block; width: 208px;">Last Name:</label>
<input type = "text" name = "LastName" value = "" required/>
</div>
<div class = "form_group" style="padding: 10px; display: block;">
<label style="float: left; padding-right: 50px; line-height: 10%; display: block; width: 208px;">Phone Number:</label>
<input type = "number" name = "PhoneNumber" value = "" required/>
</div>
<button type="submit" name="submit" >Submit</button>
</div>
</div>
</form>
</body>
</html>
Мой NodeJS Код
//jshint esversion:6
const express =require("express");
var mysql= require('mysql')
const bodyParser=require("body-parser");
const app= express();
app.use(bodyParser.urlencoded({extended: false}))
app.listen(3000, function(){
console.log("Server started on port 3000")
});
app.get("/", function(req, res){
res.sendFile(__dirname + "/index.html");
});
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'signup'
})
connection.connect(function(err){
if(err) throw err;
console.log("Connected..");
})
app.post("/submit", function(req, res){
var sql="insert into signup values('"+ req.body.FirstName +"','"+ req.body.MiddleName +"','"+ req.body.LastName +"',"+ req.body.PhoneNumber +" )";
connection.query(sql, function(err){
if(err) throw err;
res.render("index", {title: 'Data Saved', message: 'Submission Successfull' })
})
connection.end();
})
У меня есть MySql Таблица базы данных со следующими атрибутами Это изображение имеет атрибуты таблицы с именем "signup"