Node.js+Express+MySql實現(xiàn)用戶登錄注冊功能
本文實例為大家分享了Node.js實現(xiàn)用戶登錄注冊的具體代碼,供大家參考,具體內容如下
IDE:WebStorm
工程目錄:

數(shù)據(jù)庫表

Login.js:
/**
* Created by linziyu on 2017/7/8.
*/
/**
* express接收html傳遞的參數(shù)
*/
var express=require('express');
var app=express();
var mysql=require('mysql');
/**
* 配置MySql
*/
var connection = mysql.createConnection({
host : '127.0.0.1',
user : 'root',
password : '1996112lin',
database : 'mydata',
port:'3306'
});
connection.connect();
app.get('/',function (req,res) {
res.sendfile(__dirname + "/" + "index.html" );
})
/**
* 實現(xiàn)登錄驗證功能
*/
app.get('/login',function (req,res) {
var name=req.query.name;
var pwd=req.query.pwd;
var selectSQL = "select * from user where uname = '"+name+"' and pwd = '"+pwd+"'";
connection.query(selectSQL,function (err,rs) {
if (err) throw err;
console.log(rs);
console.log('OK');
res.sendfile(__dirname + "/" + "OK.html" );
})
})
app.get('/register.html',function (req,res) {
res.sendfile(__dirname+"/"+"register.html");
})
/**
* 實現(xiàn)注冊功能
*/
app.get('/register',function (req,res) {
var name=req.query.name;
var pwd=req.query.pwd;
var user={uname:name,pwd:pwd};
connection.query('insert into user set ?',user,function (err,rs) {
if (err) throw err;
console.log('ok');
res.sendfile(__dirname + "/" + "index.html" );
})
})
var server=app.listen(7744,function () {
console.log("start");
})
Index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="http://127.0.0.1:7744/login">
<input type="text" name="name"/>
<input type="text" name="pwd"/>
<input type="submit" value="提交"/>
</form>
<a href="register.html" rel="external nofollow" >注冊</a>
</body>
</html>Register.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="http://127.0.0.1:7744/register"> <input type="text" name="name"/> <input type="text" name="pwd"/> <input type="submit" value="提交"/> </form> </body> </html>
啟動后訪問:http://localhost:7744/
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Node.js實現(xiàn)登錄注冊功能
- node.js實現(xiàn)簡單登錄注冊功能
- 圖解NodeJS實現(xiàn)登錄注冊功能
- 通過Nodejs搭建網站簡單實現(xiàn)注冊登錄流程
- node.js+express+mySQL+ejs+bootstrop實現(xiàn)網站登錄注冊功能
- 利用node.js+mongodb如何搭建一個簡單登錄注冊的功能詳解
- 用node和express連接mysql實現(xiàn)登錄注冊的實現(xiàn)代碼
- node.js+jQuery實現(xiàn)用戶登錄注冊AJAX交互
- node.js實現(xiàn)登錄注冊頁面
- NodeJs+MySQL實現(xiàn)注冊登錄功能
相關文章
nodejs基于mssql模塊連接sqlserver數(shù)據(jù)庫的簡單封裝操作示例
這篇文章主要介紹了nodejs基于mssql模塊連接sqlserver數(shù)據(jù)庫的簡單封裝操作,結合實例形式分析了nodejs中mssql模塊的安裝與操作sqlserver數(shù)據(jù)庫相關使用技巧,需要的朋友可以參考下2018-01-01
node實現(xiàn)shell命令管理工具及commander.js學習
這篇文章主要為大家介紹了node實現(xiàn)shell命令管理工具及commander.js學習,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09
npm?install安裝報錯:gyp?info?it?worked?if?it?ends?with?
今天新啟動一個項目,在 npm install 安裝依賴項時出現(xiàn)報錯,所以下面這篇文章主要給大家介紹了關于npm?install安裝報錯:gyp?info?it?worked?if?it?ends?with?ok的解決方法,需要的朋友可以參考下2022-07-07
Nodejs中session的簡單使用及通過session實現(xiàn)身份驗證的方法
session的本質使用cookie來實現(xiàn)。本文給大家介紹Nodejs中session的簡單使用及通過session實現(xiàn)身份驗證的方法,對node.js session相關知識感興趣的朋友一起學習吧2016-02-02
node.js中的http.response.write方法使用說明
這篇文章主要介紹了node.js中的http.response.write方法使用說明,本文介紹了http.response.write的方法說明、語法、接收參數(shù)、使用實例和實現(xiàn)源碼,需要的朋友可以參考下2014-12-12
node.js中的buffer.toString方法使用說明
這篇文章主要介紹了node.js中的buffer.toString方法使用說明,本文介紹了buffer.toString的方法說明、語法、接收參數(shù)、使用實例和實現(xiàn)源碼,需要的朋友可以參考下2014-12-12

