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基于mssql模塊連接sqlserver數(shù)據(jù)庫(kù)的簡(jiǎn)單封裝操作示例
這篇文章主要介紹了nodejs基于mssql模塊連接sqlserver數(shù)據(jù)庫(kù)的簡(jiǎn)單封裝操作,結(jié)合實(shí)例形式分析了nodejs中mssql模塊的安裝與操作sqlserver數(shù)據(jù)庫(kù)相關(guān)使用技巧,需要的朋友可以參考下2018-01-01node實(shí)現(xiàn)shell命令管理工具及commander.js學(xué)習(xí)
這篇文章主要為大家介紹了node實(shí)現(xiàn)shell命令管理工具及commander.js學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09npm?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-07node.js express框架簡(jiǎn)介與實(shí)現(xiàn)
這篇文章主要介紹了node.js express框架簡(jiǎn)介與實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07Nodejs中session的簡(jiǎn)單使用及通過(guò)session實(shí)現(xiàn)身份驗(yàn)證的方法
session的本質(zhì)使用cookie來(lái)實(shí)現(xiàn)。本文給大家介紹Nodejs中session的簡(jiǎn)單使用及通過(guò)session實(shí)現(xiàn)身份驗(yàn)證的方法,對(duì)node.js session相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-02-02快速使用node.js進(jìn)行web開(kāi)發(fā)詳解
本篇文章主要介紹了快速使用node.js進(jìn)行web開(kāi)發(fā)詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04node.js中的http.response.write方法使用說(shuō)明
這篇文章主要介紹了node.js中的http.response.write方法使用說(shuō)明,本文介紹了http.response.write的方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12node.js中的buffer.toString方法使用說(shuō)明
這篇文章主要介紹了node.js中的buffer.toString方法使用說(shuō)明,本文介紹了buffer.toString的方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12