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

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

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)注冊(cè)功能
*/
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" >注冊(cè)</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)后訪問(wèn):http://localhost:7744/
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Node.js實(shí)現(xiàn)登錄注冊(cè)功能
- node.js實(shí)現(xiàn)簡(jiǎn)單登錄注冊(cè)功能
- 圖解NodeJS實(shí)現(xiàn)登錄注冊(cè)功能
- 通過(guò)Nodejs搭建網(wǎng)站簡(jiǎn)單實(shí)現(xiàn)注冊(cè)登錄流程
- node.js+express+mySQL+ejs+bootstrop實(shí)現(xiàn)網(wǎng)站登錄注冊(cè)功能
- 利用node.js+mongodb如何搭建一個(gè)簡(jiǎn)單登錄注冊(cè)的功能詳解
- 用node和express連接mysql實(shí)現(xiàn)登錄注冊(cè)的實(shí)現(xiàn)代碼
- node.js+jQuery實(shí)現(xiàn)用戶登錄注冊(cè)AJAX交互
- node.js實(shí)現(xiàn)登錄注冊(cè)頁(yè)面
- NodeJs+MySQL實(shí)現(xiàn)注冊(cè)登錄功能
相關(guān)文章
Nodejs封裝類似express框架的路由實(shí)例詳解
在本篇文章里小編給大家整理的是關(guān)于Nodejs封裝類似express框架的路由實(shí)例內(nèi)容,有需要的朋友們學(xué)習(xí)下。2020-01-01
Node.js操作MySQL8.0數(shù)據(jù)庫(kù)無(wú)法連接的問(wèn)題解決
使用node.js連接數(shù)據(jù)庫(kù)MySQL 8時(shí)候,顯示報(bào)錯(cuò) ER_NOT_SUPPORTED_AUTH_MODE,本文就來(lái)介紹一下解決方法,感興趣的可以了解一下2023-10-10
Node.js+jade抓取博客所有文章生成靜態(tài)html文件的實(shí)例
下面小編就為大家?guī)?lái)一篇Node.js+jade抓取博客所有文章生成靜態(tài)html文件的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
關(guān)于npm主版本升級(jí)及其相關(guān)知識(shí)點(diǎn)總結(jié)
npm是Node.js默認(rèn)的包管理器,以javascript?編寫的軟件包管理系統(tǒng)用于分享和使用代碼,下面這篇文章主要給大家介紹了關(guān)于npm主版本升級(jí)及其相關(guān)知識(shí)點(diǎn)總結(jié)的相關(guān)資料,需要的朋友可以參考下2022-12-12
nodejs實(shí)現(xiàn)發(fā)送郵箱驗(yàn)證碼功能
這篇文章主要為大家詳細(xì)介紹了nodejs實(shí)現(xiàn)發(fā)送郵箱驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
node項(xiàng)目使用http模塊發(fā)送get-post請(qǐng)求方式
這篇文章主要介紹了node項(xiàng)目使用http模塊發(fā)送get-post請(qǐng)求方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-09-09
一文詳解Node中module.exports和exports區(qū)別
這篇文章主要介紹了一文詳解Node中module.exports和exports區(qū)別2023-03-03
electron安裝報(bào)錯(cuò)終極解決辦法詳細(xì)講解
當(dāng)使用npm安裝electron時(shí),有時(shí)候會(huì)遇到各種各樣的錯(cuò)誤,如網(wǎng)絡(luò)錯(cuò)誤、權(quán)限錯(cuò)誤等等,這篇文章主要給大家介紹了關(guān)于electron安裝報(bào)錯(cuò)終極解決辦法的相關(guān)資料,需要的朋友可以參考下2024-09-09

