Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74074

Object not found! Error when i try to sumbit a form it was not going to that addresss

$
0
0

I downloaded the SB Admin template from the internet and edited it. After editing, I tried to run a server file which has this code:

var express = require('express')
var sql = require('mysql')
var bodyParser = require('body-parser')

//initializing express into App
var app = express()

//using bodyparser to get the details from a page
app.use(bodyParser());

//for the access of server tgo other site cross origin has to be defined
app.all("/*", function (req, res, next) {
    res.header("Access-Control-Allow-Headers", "Content-Type");
    res.header("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
    res.header("Access-Control-Allow-Origin", "*");
    return next();
})

//setting up post request
app.post("/registerData", function (req, response) {
    var first_name = req.body.first_name;
    var last_name = req.body.last_name;
    var email = req.body.email_;
    var password = req.body.password_;
    var cpassword = req.body.password_1;
    var create_table = "CREATE TABLE register_info (sno int(255),fname varchar(255),lname varchar(255),email varchar(255),password varchar(255),cpassword varchar(255))"
    db_connection.query(create_table, function (err, res1) {
        if (err) {
            db_connection.query("ALTER TABLE register_info AUTO_INCREMENT=1;")
            var insert_query = "INSERT INTO register_info(sno,fname,lname,email,password,cpassword) VALUES(" + "1" + "," + "'" + first_name + "'" + "," + "'" + last_name + "'" + "," + "'" + email + "'" + "," + "'" + password + "'" + "," + "'" + cpassword + "'" + "," + ")"
            db_connection.query(insert_query, function (err, res2) {
                if (err) {
                    var insert_query1 = "INSERT INTO register_info(sno,fname,lname,email,password,cpassword) VALUES(" + "" + "," + "'" + first_name + "'" + "," + "'" + last_name + "'" + "," + "'" + email + "'" + "," + "'" + password + "'" + "," + "'" + cpassword + "'" + "," + ")"
                    db_connection.query(insert_query1, function (err, res3) {
                        if (err) {
                            console.log("Values cannot be Inserted after all Attempts")
                        } else {
                            console.log("Data Successfully updated after Final attempt")
                        }
                    })
                } else {
                    console.log("Data Inserted")
                }
            })
        } else {
            db_connection.query("ALTER TABLE register_info AUTO_INCREMENT=1")
            var insert_query = "INSERT INTO register_info(sno,fname,lname,email,password,cpassword) VALUES(" + "1" + "," + "'" + first_name + "'" + "," + "'" + last_name + "'" + "," + "'" + email + "'" + "," + "'" + password + "'" + "," + "'" + cpassword + "'" + "," + ")"
            db_connection.query(insert_query, function (err, res2) {
                if (err) {
                    var insert_query1 = "INSERT INTO register_info(sno,fname,lname,email,password,cpassword) VALUES(" + "" + "," + "'" + first_name + "'" + "," + "'" + last_name + "'" + "," + "'" + email + "'" + "," + "'" + password + "'" + "," + "'" + cpassword + "'" + "," + ")"
                    db_connection.query(insert_query1, function (err, res3) {
                        if (err) {
                            console.log("Values cannot be Inserted after all Attempts")
                        } else {
                            console.log("Data Successfully updated after Final attempt")
                        }
                    })
                } else {
                    console.log("Data Inserted")
                }
            })
        }
    })
})

//setting up database for connection
var db_connection = sql.createConnection({
    "host": "localhost",
    "user": "root",
    "password": "",
    "database": "project"
})

//initializing db_connection (database connection)
db_connection.connect(function (err) {
    if (err) {
        console.log("Database is not Accessed")
    } else {
        console.log("Database Access Granted")
    }
})


app.listen(1337, function (err) {
    if (err) {
        console.log("Error in Port Connection")
    } else {
        console.log("Port connected : 1337")
    }
})

But when I try to submit the data through a register form which has this code:

'<div class="container">
<div class="card card-register mx-auto mt-5">
  <div class="card-header">Register an Account</div>
  <div class="card-body">
    <form action="http://127.0.0.1/1337/registerData" method="POST" id="form_info">
      <div class="form-group">
        <div class="form-row">
          <div class="col-md-6">
            <div class="form-label-group">
              <input type="text" name="first_name" id="firstName" class="form-control" placeholder="First name" required="required" autofocus="autofocus">
              <label for="firstName">First name</label>
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-label-group">
              <input type="text" name="last_name" id="lastName" class="form-control" placeholder="Last name" required="required">
              <label for="lastName">Last name</label>
            </div>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="form-label-group">
          <input type="email" name="email_" id="inputEmail" class="form-control" placeholder="Email address" required="required">
          <label for="inputEmail">Email address</label>
        </div>
      </div>
      <div class="form-group">
        <div class="form-row">
          <div class="col-md-6">
            <div class="form-label-group">
              <input type="password" name="password_" id="inputPassword" class="form-control" placeholder="Password" required="required">
              <label for="inputPassword">Password</label>
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-label-group">
              <input type="password" name="password_1" id="confirmPassword" class="form-control" placeholder="Confirm password" required="required">
              <label for="confirmPassword">Confirm password</label>
            </div>
          </div>
        </div>
      </div>
      <input type="submit" class="btn btn-primary btn-block" id="rgstr_btn" value="Reegister">
    </form>
    <div class="text-center">
      <a class="d-block small mt-3" href="login.html">Login Page</a>
      <a class="d-block small" href="forgot-password.html">Forgot Password?</a>
    </div>
  </div>
</div>

The page gives the error:

Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404 127.0.0.1 Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.8

I cannot understand where I am going wrong, please help, I am new to programming and thanks in advance :)


Viewing all articles
Browse latest Browse all 74074

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>