投稿時間:2022-08-06 16:18:44 RSSフィード2022-08-06 16:00 分まとめ(17件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… TokyoTool、NOMAD製「iPhone 13/13 Pro」用レザーケースの15%オフセールを開催中 https://taisy0.com/2022/08/06/159876.html iphone 2022-08-06 06:16:12
python Pythonタグが付けられた新着投稿 - Qiita tkinterでラジオボタンを使う https://qiita.com/koikeke0911/items/44a5bc6eb285ec20ebb7 textv 2022-08-06 15:45:44
AWS AWSタグが付けられた新着投稿 - Qiita AWS はじめての継続的デリバリーパイプライン(CICD)やってみた https://qiita.com/kangaezaru/items/f104d91da8a575984405 conti 2022-08-06 15:49:03
海外TECH DEV Community Creating a Login and Registration Form with Node.js, Express.js and MySQL database https://dev.to/jahongir2007/creating-a-login-and-registration-form-with-nodejs-expressjs-and-mysql-database-160n Creating a Login and Registration Form with Node js Express js and MySQL databaseToday we will learn how to create a login and registration form with node js express js and mysql Our goalEntering the data entered by the user in the registration form into the MySQL database after checking whether such information has been entered into the database In the login form checking whether the data entered by the user is available in the MySQL database and working with sessions We will download the necessary programsCreating our app folder mkdir myform amp amp cd myformCreating a Node Project and Initialize npm init yFor this we need Node js AppServ and MySQL database We download some libraries from NPM npm i express mysql cookie parser express session body parser We create a database to store data in MySQLIn the SQL editor of phpMyAdmin we use the following SQL code CREATE DATABASE myformAfter creating a database named myform we create a table named users inside it CREATE TABLE users id INT UNSIGNED AUTO INCREMENT PRIMARY KEY firstname VARCHAR NOT NULL lastname VARCHAR NOT NULL username VARCHAR NOT NULL password VARCHAR NOT NULL reg date TIMESTAMP DEFAULT CURRENT TIMESTAMP ON UPDATE CURRENT TIMESTAMP Creating web server in Node js and Express jsTo create a web server we create a file named server js server jsconst express require express const app express app get req res gt res send Hello world app listen gt console log Server running on port Now we will create a registration form on the home page of this server For this we create a file named register html and insert the following codes into it lt register html gt lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt h gt Login and register form with Node js Express js and MySQL lt h gt lt h gt Register form lt h gt lt form action register method POST gt lt div class form group mb gt lt label gt First name lt label gt lt input type text class form control placeholder First name name firstName gt lt div gt lt div class form group mb gt lt label gt Last name lt label gt lt input type text class form control placeholder Last name name lastName gt lt div gt lt div class form group mb gt lt label gt Username lt label gt lt input type text class form control placeholder Username name userName gt lt div gt lt div class form group mb gt lt label gt Password lt label gt lt input type password class form control placeholder Password name password gt lt div gt lt div class d grid mt gt lt button type submit class btn btn primary form control gt Submit lt button gt lt div gt lt form gt lt div gt lt body gt lt html gt We upload the register html file to the home page of our web server and use body parser to extract the user data from it const express require express var parseUrl require body parser const app express let encodeUrl parseUrl urlencoded extended false app get req res gt res sendFile dirname register html app post register encodeUrl req res gt var firstName req body firstName var lastName req body lastName var userName req body userName var password req body password app listen gt console log Server running on port We enter the data into the MySQL databaseWe check the database to see if this user has registered before const express require express const cookieParser require cookie parser const sessions require express session const http require http var parseUrl require body parser const app express var mysql require mysql let encodeUrl parseUrl urlencoded extended false session middlewareapp use sessions secret thisismysecrctekey saveUninitialized true cookie maxAge hours resave false app use cookieParser var con mysql createConnection host localhost user root my username password my password database myform app get req res gt res sendFile dirname register html app post register encodeUrl req res gt var firstName req body firstName var lastName req body lastName var userName req body userName var password req body password con connect function err if err console log err checking user already registered or no con query SELECT FROM users WHERE username userName AND password password function err result if err console log err if Object keys result length gt res sendFile dirname failReg html else creating user page in userPage function function userPage We create a session for the dashboard user page page and save the user data to this session req session user firstname firstName lastname lastName username userName password password res send lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt h gt Hi req session user firstname req session user lastname lt h gt lt a href gt Log out lt a gt lt div gt lt body gt lt html gt inserting new user data var sql INSERT INTO users firstname lastname username password VALUES firstName lastName userName password con query sql function err result if err console log err else using userPage function for creating user page userPage app listen gt console log Server running on port lt failReg html gt lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt center gt lt h class text danger gt This user already registered lt h gt lt a href gt Try again lt a gt lt center gt lt div gt lt body gt lt html gt All of the above was code written for the registration form We will create a login formTo create a login form first create a file named login html and add the following codes to it lt login html gt lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt h gt Login and register form with Node js Express js and MySQL lt h gt lt h gt Login form lt h gt lt form action dashboard method POST gt lt div class form group mb gt lt label gt Username lt label gt lt input type text class form control placeholder Username name userName gt lt div gt lt div class form group mb gt lt label gt Password lt label gt lt input type password class form control placeholder Password name password gt lt div gt lt div class d grid mt gt lt button type submit class btn btn primary form control gt Submit lt button gt lt div gt lt form gt lt div gt lt body gt lt html gt Now we enter the codes of the login form in our server js file server js upload login html file to login pageapp get login req res gt res sendFile dirname login html get user data to dashboard pageapp post dashboard encodeUrl req res gt var userName req body userName var password req body password con connect function err if err console log err get user data from MySQL database con query SELECT FROM users WHERE username userName AND password password function err result if err console log err creating userPage function to create user page function userPage We create a session for the dashboard user page page and save the user data to this session req session user firstname result firstname get MySQL row data lastname result lastname get MySQL row dataa username userName password password res send lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt h gt Hi req session user firstname req session user lastname lt h gt lt a href gt Log out lt a gt lt div gt lt body gt lt html gt if Object keys result length gt userPage else res sendFile dirname failLog html lt failLog html gt lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt center gt lt h class text danger gt This username or password error lt h gt lt a href gt Try again lt a gt lt center gt lt div gt lt body gt lt html gt All the code in server js const express require express const cookieParser require cookie parser const sessions require express session const http require http var parseUrl require body parser const app express var mysql require mysql const encode require punycode let encodeUrl parseUrl urlencoded extended false session middlewareapp use sessions secret thisismysecrctekey saveUninitialized true cookie maxAge hours resave false app use cookieParser var con mysql createConnection host localhost user root my username password my password database myform app get req res gt res sendFile dirname register html app post register encodeUrl req res gt var firstName req body firstName var lastName req body lastName var userName req body userName var password req body password con connect function err if err console log err checking user already registered or no con query SELECT FROM users WHERE username userName AND password password function err result if err console log err if Object keys result length gt res sendFile dirname failReg html else creating user page in userPage function function userPage We create a session for the dashboard user page page and save the user data to this session req session user firstname firstName lastname lastName username userName password password res send lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt h gt Hi req session user firstname req session user lastname lt h gt lt a href gt Log out lt a gt lt div gt lt body gt lt html gt inserting new user data var sql INSERT INTO users firstname lastname username password VALUES firstName lastName userName password con query sql function err result if err console log err else using userPage function for creating user page userPage app get login req res gt res sendFile dirname login html app post dashboard encodeUrl req res gt var userName req body userName var password req body password con connect function err if err console log err con query SELECT FROM users WHERE username userName AND password password function err result if err console log err function userPage We create a session for the dashboard user page page and save the user data to this session req session user firstname result firstname lastname result lastname username userName password password res send lt DOCTYPE html gt lt html lang en gt lt head gt lt title gt Login and register form with Node js Express js and MySQL lt title gt lt meta charset UTF gt lt meta name viewport content width device width initial scale gt lt link href dist css bootstrap min css rel stylesheet gt lt head gt lt body gt lt div class container gt lt h gt Hi req session user firstname req session user lastname lt h gt lt a href gt Log out lt a gt lt div gt lt body gt lt html gt if Object keys result length gt userPage else res sendFile dirname failLog html app listen gt console log Server running on port Thank you for your attention 2022-08-06 06:25:37
海外TECH CodeProject Latest Articles Git – Comparing Visual Studio 2022 with MeGit/EGit and SourceTree https://www.codeproject.com/Articles/5338960/Git-Comparing-Visual-Studio-2022-with-MeGit-EGit-a comparing 2022-08-06 06:41:00
海外ニュース Japan Times latest articles Taiwan says China simulating attack on main island in drills https://www.japantimes.co.jp/news/2022/08/06/asia-pacific/politics-diplomacy-asia-pacific/china-taiwan-military-drills-simulated-attack/ Taiwan says China simulating attack on main island in drillsThe Taiwanese army responded by sending air patrols and naval ships deploying land base missile systems and issuing radio warnings the Defense Ministry said in a 2022-08-06 15:23:50
ニュース BBC News - Home NHS 111 software outage confirmed as cyber-attack https://www.bbc.co.uk/news/uk-wales-62442127?at_medium=RSS&at_campaign=KARANGA attackthe 2022-08-06 06:24:37
ニュース BBC News - Home Bangladesh: Samira Islam, 20, third family member to die https://www.bbc.co.uk/news/uk-wales-62442128?at_medium=RSS&at_campaign=KARANGA carbon 2022-08-06 06:53:43
ニュース BBC News - Home Bridgend avant garde hairdresser nominated for UK award https://www.bbc.co.uk/news/uk-wales-62423394?at_medium=RSS&at_campaign=KARANGA awardshelley 2022-08-06 06:15:27
ニュース BBC News - Home Cameron Norrie to face Daniil Medvedev in Los Cabos final https://www.bbc.co.uk/sport/tennis/62446769?at_medium=RSS&at_campaign=KARANGA mexico 2022-08-06 06:48:02
北海道 北海道新聞 大谷は5打数1安打 マリナーズ戦 https://www.hokkaido-np.co.jp/article/714983/ 打数 2022-08-06 15:28:00
北海道 北海道新聞 釧路管内222人、根室管内64人が感染 新型コロナ https://www.hokkaido-np.co.jp/article/714980/ 根室管内 2022-08-06 15:19:56
北海道 北海道新聞 上川管内546人感染 新型コロナ https://www.hokkaido-np.co.jp/article/714982/ 上川管内 2022-08-06 15:19:00
北海道 北海道新聞 日大三島3―10国学院栃木 国学院栃木が逆転勝ち https://www.hokkaido-np.co.jp/article/714981/ 国学院栃木 2022-08-06 15:17:00
北海道 北海道新聞 後志管内251人感染 新型コロナ https://www.hokkaido-np.co.jp/article/714979/ 新型コロナウイルス 2022-08-06 15:15:00
北海道 北海道新聞 池田町のワイン祭り3年連続中止 安全性確保できず 観光協会「心苦しい」 https://www.hokkaido-np.co.jp/article/714974/ 観光協会 2022-08-06 15:02:32
IT 週刊アスキー 【8月の劇場アニメ】超話題の「ワンピース」最新作が登場! https://weekly.ascii.jp/elem/000/004/100/4100985/ 京都アニメーション 2022-08-06 15:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)