Node.js+Express+MySql實(shí)現(xiàn)用戶登錄注冊功能
本文實(shí)例為大家分享了Node.js實(shí)現(xiàn)用戶登錄注冊的具體代碼,供大家參考,具體內(nèi)容如下
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" );
})
/**
* 實(shí)現(xiàn)登錄驗(yà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");
})
/**
* 實(shí)現(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>
啟動(dòng)后訪問:http://localhost:7744/
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Node.js實(shí)現(xiàn)登錄注冊功能
- node.js實(shí)現(xiàn)簡單登錄注冊功能
- 圖解NodeJS實(shí)現(xiàn)登錄注冊功能
- 通過Nodejs搭建網(wǎng)站簡單實(shí)現(xiàn)注冊登錄流程
- node.js+express+mySQL+ejs+bootstrop實(shí)現(xiàn)網(wǎng)站登錄注冊功能
- 利用node.js+mongodb如何搭建一個(gè)簡單登錄注冊的功能詳解
- 用node和express連接mysql實(shí)現(xiàn)登錄注冊的實(shí)現(xiàn)代碼
- node.js+jQuery實(shí)現(xiàn)用戶登錄注冊AJAX交互
- node.js實(shí)現(xiàn)登錄注冊頁面
- NodeJs+MySQL實(shí)現(xiàn)注冊登錄功能
相關(guān)文章
nodejs基于mssql模塊連接sqlserver數(shù)據(jù)庫的簡單封裝操作示例
這篇文章主要介紹了nodejs基于mssql模塊連接sqlserver數(shù)據(jù)庫的簡單封裝操作,結(jié)合實(shí)例形式分析了nodejs中mssql模塊的安裝與操作sqlserver數(shù)據(jù)庫相關(guān)使用技巧,需要的朋友可以參考下2018-01-01
node實(shí)現(xiàn)shell命令管理工具及commander.js學(xué)習(xí)
這篇文章主要為大家介紹了node實(shí)現(xiàn)shell命令管理工具及commander.js學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
npm?install安裝報(bào)錯(cuò):gyp?info?it?worked?if?it?ends?with?
今天新啟動(dòng)一個(gè)項(xiàng)目,在 npm install 安裝依賴項(xiàng)時(shí)出現(xiàn)報(bào)錯(cuò),所以下面這篇文章主要給大家介紹了關(guān)于npm?install安裝報(bào)錯(cuò):gyp?info?it?worked?if?it?ends?with?ok的解決方法,需要的朋友可以參考下2022-07-07
node.js express框架簡介與實(shí)現(xiàn)
這篇文章主要介紹了node.js express框架簡介與實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
Nodejs中session的簡單使用及通過session實(shí)現(xiàn)身份驗(yàn)證的方法
session的本質(zhì)使用cookie來實(shí)現(xiàn)。本文給大家介紹Nodejs中session的簡單使用及通過session實(shí)現(xiàn)身份驗(yàn)證的方法,對node.js session相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2016-02-02
node.js中的http.response.write方法使用說明
這篇文章主要介紹了node.js中的http.response.write方法使用說明,本文介紹了http.response.write的方法說明、語法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12
node.js中的buffer.toString方法使用說明
這篇文章主要介紹了node.js中的buffer.toString方法使用說明,本文介紹了buffer.toString的方法說明、語法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12

