0

This is the whole code is for entering data into mysql db, whenever I try to submit the data via form the web page just keeps on loading and loading while backend receives

body-parser deprecated undefined extended: provide extended option node_modules\express\lib\router\layer.js:95:5 I followed the tutorial throughout to the end just the last part not working, in sql db i can enter data manually but just stuck here with backend post req handling,

The main issue must be comment (post handling)

//previous imports (following this tutorial https://www.youtube.com/watch?v=Mn0rdbJPWEo)

import es6Renderer from 'express-es6-template-engine';


// latest imports

import mysql, { createConnection } from "mysql";

import express from 'express';
const app = express();

import bodyParser from 'body-parser'
const encoder = bodyParser.urlencoded

// connecting to db

const Connection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "nodejs"
})

// connection resposne to databse that I've created

Connection.connect(function(error){
    if(error) throw error
    else console.log("Korewa Korewa OWO)/ Database connected desu ne!")
})

// rendering 

app.use(express.static('public'));
app.engine('html', es6Renderer);
app.set('/html/struct', 'views');
app.set('view engine', 'html');
 
app.get('/', function(req, res) {

  res.render('struct');
  
});

app.get('/myacc', function(req, res) {
   res.render('myacc')
   
});

// handing post
app.post("/",encoder, function(req,res){

    let User_Email = req.body.User_Email
    let Username = req.body.Username
    let P_Password = req.body.P_Password
    let C_password = req.body.C_password

    Connection.query("select * from loginuser where User_Email = ? and Username = ? and P_Password = ?",[User_Email, Username, P_Password], 
    function(error, results, fields){
        if(results.length > 0){
            res.redirect('/welcome')
            
        }
        else if(error) throw error
        
        else {
                res.redirect("/leno")
        }
        res.end();
    })
})

app.get("/welcome", function(req, res){
    console.log("USer Signed Up")
})

app.get("/leno", function(req, res){
    console.log("result lenght 0")
})
// set app port

app.listen(4000);

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • ig it did, or nope. "result lenght 0" meaning results if(results.length < 0) or anything else, and db no getting anything – Fenguin Phoenix Oct 02 '22 at 11:30
  • If you now have a different problem, please update your question or ask a new one. From your comment, it seems like your problem was fixed and a new one came up. The new problem might be because of mismatched fields in a form, a typo in a database name, or any number of things. – FlippingBinary Oct 04 '22 at 03:00
  • nope ig idk, I just changed tutorial for 4th time now but body-parser deprecated undefined extended: provide extended option was fixed – Fenguin Phoenix Oct 05 '22 at 09:57

0 Answers0