Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Title</title>
- <style type="text/css">
- </style>
- <meta name="robots" content="dofollow" />
- <meta name="googlebot" content="dofollow" />
- <meta name="description" content=" " />
- <meta name="google" content="nositelinkssearchbox" />
- </meta>
- </body>
- <body>
- <form id="data-form" action="http://x.x.x.x:3000/form" method="POST">
- <input type="text" name="uid" value="13">
- URL:<br>
- <input type="text" name="urll" value="Add"><br>
- Title:<br>
- <input type="text" name="title" value="Title"><br>
- Description:<br>
- <input type="text" name="blurb" value="Summary"><br>
- Tags:<br>
- <input type="text" name="tags" value="Three"><br>
- <br>
- Choose a thumbnail<br>
- <br>
- <br>
- <input type="submit" value="Submit" />
- </form>
- </body>
- </html>
- var express = require('express');
- var bodyParser = require('body-parser');
- var app = express();
- var jsonParser = bodyParser.json();
- var urlencodedParser = bodyParser.urlencoded({ extended: true });
- var mysql = require('mysql');
- // Configure MySQL connection
- var pool = mysql.createPool({
- connectionLimit: 50,
- host: 'x.x.x.x',
- user: 'xx',
- password: 'xxxx',
- database: 'rawdata'
- });
- //Establish MySQL connection
- pool.getConnection(function(err, connection) {
- if (err)
- throw err;
- else {
- console.log('Connected to MySQL');
- // Start the app when connection is ready
- app.listen(3000);
- console.log('Server listening on port 3000');
- }
- });
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use(bodyParser.json({ type: 'application/*+json' }));
- //allow express to access our file
- app.get('/form/form.html', function(req, res) {
- res.sendFile(__dirname + "/form/" + "form.html");
- });
- //This sends the user information to the path
- app.post('/form', urlencodedParser, function(req, res, connection){
- var jsondata = req.body;
- var values = [];
- values.push([jsondata.uid,jsondata.title,jsondata.tags]);
- //Bulk insert using nested array [ [a,b],[c,d] ] will be flattened to (a,b),(c,d)
- pool.query('INSERT INTO raw (uid, title, tags) VALUES ?', [values], function(err,result) {
- if(err) {
- console.log('Error' + err + req.body);
- }
- else {
- res.status(200).send('Done');
- }
- });
- });
Add Comment
Please, Sign In to add comment