I am new to nodejs.please help. Here is my html and node.js code. I want to send email and password from login.html(client) to login.js(server) and validate from table storing email and password.
login.html
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="/loginstyle.css" /> </head> <body> <form class="css" method="post" action="http://localhost:9383/valid" > <fieldset > <input type="text" name="email" class="inputemail" placeholder="Email" /> </fieldset> <fieldset > <input type="password" name="pass" class="inputpassword" placeholder="Password" /> </fieldset > <fieldset > <button type="submit" class="submit">Submit</button> </fieldset> </form> </body> </html> login.js
var express = require('express') , app = express() , mysql = require("mysql"); app.get('/loginme', function (req, res) { res.sendfile(__dirname + '/loginmysql.html'); }); app.post('/valid', function (req, res) { console.log("hello"); var username=req.body.email; var password=req.body.pass; var connection = mysql.createConnection({ "hostname": "localhost", "user": "root", "password": "123", "database": "login" }); connection.connect(); connection.query('SELECT * FROM id WHERE email=? AND password=?', [username,password], function(err, rows){ if (err){ throw err; }else{ for (var i in rows) { console.log('name: ', rows[i].name); name=rows[i].name; res.redirect('/option'); } } }); connection.end(); });
/option. Presumably it does the former. What error does it throw? (Make sure you look at the node.js console).