Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------Connection.js-------------------------------------------
- var sql = require('mysql');
- var exp = require('express');
- var path = require('path');
- var http = require('http');
- var fs = require('fs');
- var router = exp();
- // router.use('/public', exp.static(path.join(__dirname, 'public')));
- //Database info
- var connection = sql.createConnection
- ({
- host: 'localhost',
- user: 'root',
- password: 'root',
- database: 'quiz'
- });
- //Connect to Database
- connection.connect(function (err) {
- if (err) throw err;
- console.log("Connected!");
- });
- //Create the server
- http.createServer(function (req, res) {
- //Open a file on the server and return it's content:
- fs.readFile('public/AdminPanel.html', function (err, data) {
- res.writeHead(200, { 'Content-Type': 'text/html' });
- res.write(data);
- return res.end();
- });
- }).listen(8080);
- //function for onclick button CreateUser
- function CreateUser() {
- alert("Create User");
- console.log("Create User");
- }
- //function for onclick button EditUser
- function EditUser() {
- alert("Edit User");
- console.log("Edit User");
- }
- //function for onclick button DeactivateUser
- function DeactivateUser() {
- connection.query("SELECT * FROM user", function (err, result, fields) {
- if (err) throw err;
- console.log(result);
- });
- console.log("Deactivate User");
- alert("Deactivate User");
- }
- -------------------------------------AdminPanel.html-------------------------------------------
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <script src="Connection.js"></script>
- <title>Admin Panel</title>
- </head>
- <body>
- <button onclick="CreateUser()"> Create User</button>
- <button onclick="EditUser()"> Edit User</button>
- <button onclick="DeactivateUser()"> Deactivate User</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement