title: cannot post login form html node js
body: <p>I have seen the same problem a few times on stack, but not one that seems to help me. I have a register form with a submit button that I am trying to get to submit data to MySQL and take me to the login page using node js. It successfully submits data, but will say Cannot POST / loginform.html.</p>
  
  <p>Here is my index.html (register form)</p>
  
  <pre><code>&lt;form target = "_blank" method = "post" action="//localhost:3000/LoginForm.html" onsubmit = "return validationRedirect();"&gt;
    &lt;div class="container"&gt;
      &lt;h1&gt;Register&lt;/h1&gt;
      &lt;p&gt;Please fill out this form to create an account for BAH University.&lt;/p&gt;
      &lt;hr&gt;
  
      &lt;img style="float: right; margin: 40px 20px 20px 20px;" src="views/photos/furman.jpg" width="770" height="310" border = "4" /&gt;
      &lt;img style="float: right; margin: -24px 20px 0px 0px;" src="views/photos/furman1.jpg" width="770" height="310" border = "4" /&gt;
  
      &lt;div class="relative"&gt;&lt;em&gt;&lt;i&gt;Committed to Excellence&lt;/i&gt;&lt;/em&gt;&lt;/div&gt;
  
      &lt;label for="username"&gt;&lt;b&gt;Username&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="text" style="width: 600px" placeholder="Enter Username" name="Username" required&gt;
      &lt;br&gt;
  
      &lt;label for="psw"&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="password" style="width: 600px" placeholder="Enter Password" name="Password" required&gt;
      &lt;br&gt;  
  
      &lt;label for="pswrepeat"&gt;&lt;b&gt;Repeat Password&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="password" style="width: 600px" placeholder="Repeat Password" name="Passwordrpt" required&gt;
      &lt;br&gt; 
  
      &lt;label for="lastName"&gt;&lt;b&gt;Last Name&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="text" style="width: 600px" placeholder="Last Name" name="LastName" required&gt;
      &lt;br&gt;
  
      &lt;label for="firstName"&gt;&lt;b&gt;First Name&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="text" style="width: 600px" placeholder="First Name" name="FirstName" required&gt;
      &lt;br&gt;
  
      &lt;label for="address"&gt;&lt;b&gt;Address&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="text" style="width: 600px" placeholder="Address" name="Address"&gt;
      &lt;br&gt;
  
      &lt;label for="email"&gt;&lt;b&gt;Email&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="text" style="width: 600px" placeholder="Email" name="Email" required&gt;
      &lt;br&gt;
  
      &lt;label for="phone"&gt;&lt;b&gt;Phone&lt;/b&gt;&lt;/label&gt;
      &lt;br&gt;
      &lt;input type="text" style="width: 600px" placeholder="Phone" name="Phone" required&gt;
      &lt;hr&gt;
  
      &lt;input name = "submit" type = "submit" value = "Register" class = "savebtn"&gt;
      &lt;!--&lt;a&gt;&lt;input type ="button" value = "Login" class = "registerbtn" onclick = "window.location.href ='LoginForm.html'"&gt;&lt;/a&gt;--&gt;
  
    &lt;/div&gt;
  
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And my LoginForm.html</p>
  
  <pre><code>&lt;form action="/LoginForm" method = "post"&gt;
  
    &lt;div class="container"&gt;
      &lt;h1&gt;Login&lt;/h1&gt;
  
      &lt;img src="views/photos/furman.jpg" alt="BAH" style="float: left; margin: 10px -30px 45px 20px; width:
      708px;height:365px;" border = "4"&gt;
      &lt;img src="views/photos/furman1.jpg" alt="BAH" style="float: left; margin: 10px -30px 45px 20px; width:
      708px;height:365px;" border = "4"&gt;
      &lt;/br&gt;&lt;/br&gt;&lt;/br&gt;
  
      &lt;label for="username"&gt;&lt;b&gt;Username&lt;/b&gt;&lt;/label&gt;
      &lt;input type="text" placeholder="Enter Username" name="username" required&gt;
  
      &lt;label for="psw"&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/label&gt;
      &lt;input type="password" placeholder="Enter Password" name="psw" required&gt;
  
      &lt;input type = "submit" value = "Login" class = "newlogbtn"&gt;
      &lt;a&gt;&lt;input type="button" class="newuserbtn" value = "New User" button onclick = "window.location.href ='index.html'"&gt;&lt;/a&gt;
  
    &lt;/div&gt;
  
    &lt;div class="container" style="background-color: white"&gt;
      &lt;bgcolor = "black"&gt;&lt;/bgcolor&gt;
    &lt;/div&gt;
  
  
  
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>var express = require('express');
  var app = express();
  
  var router = express.Router();
  var mysql = require('mysql');
  var http = require('http');
  
  var con = mysql.createConnection({
      host: "localhost",
      user: "root",
      password: "",
      database: ""
  })
  app.use(express.static(__dirname + '/public')); //for css and photos directory
  var bodyParser = require("body-parser");
  app.use(bodyParser.urlencoded({ extended: false }));
  
  app.get('/', function (req, res) {
      res.sendFile(__dirname + '/index.html');
  });
  app.get('/LoginForm.html', function (req, res) {
      res.sendFile(__dirname + '/LoginForm.html');
  });
  
  app.post('/RegisterForm', function (req, res) {
      let name = req.body.Username + ' ' + req.body.Password + ' ' + req.body.Passwordrpt + ' ' + req.body.FirstName + ' ' + req.body.LastName + ' ' + req.body.Address + ' ' + req.body.Email + ' ' + req.body.Phone;
  
      res.send(name + ' Submitted Successfully!');
  
      //router.post('/registerform', function(req, res, next) {
      con.connect(function(err) {
          if (err) throw  err;
          console.log("connected");
          var sql = "INSERT INTO persontable (Username, Password, LastName, FirstName, Address, Email, Phone)VALUES('"+req.body.Username+"','"+req.body.Password+"', '"+req.body.LastName+"', '"+req.body.FirstName+"', '"+req.body.Address+"', '"+req.body.Email+"', '"+req.body.Phone+"')";
          con.query(sql, function(err, result)  {
              if(err) throw err;
              console.log("Register information saved.");
          });
      });
    //})    
  });
  
  var server = app.listen(3000, function () {
      console.log('Node server is running on port 3000..');
  });
  </code></pre>
  
  <p>Thanks in advance for the help.</p>