Guest User

Untitled

a guest
Feb 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5.  
  6. <title>Title</title>
  7.  
  8. <style type="text/css">
  9.  
  10. </style>
  11.  
  12. <meta name="robots" content="dofollow" />
  13. <meta name="googlebot" content="dofollow" />
  14.  
  15. <meta name="description" content=" " />
  16.  
  17. <meta name="google" content="nositelinkssearchbox" />
  18.  
  19. </meta>
  20. </body>
  21.  
  22. <body>
  23.  
  24. <form id="data-form" action="http://x.x.x.x:3000/form" method="POST">
  25.  
  26. <input type="text" name="uid" value="13">
  27.  
  28. URL:<br>
  29. <input type="text" name="urll" value="Add"><br>
  30.  
  31. Title:<br>
  32. <input type="text" name="title" value="Title"><br>
  33.  
  34. Description:<br>
  35. <input type="text" name="blurb" value="Summary"><br>
  36.  
  37. Tags:<br>
  38. <input type="text" name="tags" value="Three"><br>
  39.  
  40. <br>
  41. Choose a thumbnail<br>
  42. <br>
  43.  
  44. <br>
  45. <input type="submit" value="Submit" />
  46.  
  47. </form>
  48. </body>
  49. </html>
  50.  
  51. var express = require('express');
  52. var bodyParser = require('body-parser');
  53. var app = express();
  54.  
  55. var jsonParser = bodyParser.json();
  56. var urlencodedParser = bodyParser.urlencoded({ extended: true });
  57. var mysql = require('mysql');
  58.  
  59. // Configure MySQL connection
  60. var pool = mysql.createPool({
  61. connectionLimit: 50,
  62. host: 'x.x.x.x',
  63. user: 'xx',
  64. password: 'xxxx',
  65. database: 'rawdata'
  66. });
  67.  
  68. //Establish MySQL connection
  69. pool.getConnection(function(err, connection) {
  70. if (err)
  71. throw err;
  72. else {
  73. console.log('Connected to MySQL');
  74. // Start the app when connection is ready
  75. app.listen(3000);
  76. console.log('Server listening on port 3000');
  77. }
  78. });
  79.  
  80. app.use(bodyParser.urlencoded({ extended: true }));
  81.  
  82. app.use(bodyParser.json({ type: 'application/*+json' }));
  83.  
  84. //allow express to access our file
  85. app.get('/form/form.html', function(req, res) {
  86. res.sendFile(__dirname + "/form/" + "form.html");
  87. });
  88.  
  89. //This sends the user information to the path
  90. app.post('/form', urlencodedParser, function(req, res, connection){
  91.  
  92. var jsondata = req.body;
  93. var values = [];
  94.  
  95. values.push([jsondata.uid,jsondata.title,jsondata.tags]);
  96.  
  97. //Bulk insert using nested array [ [a,b],[c,d] ] will be flattened to (a,b),(c,d)
  98. pool.query('INSERT INTO raw (uid, title, tags) VALUES ?', [values], function(err,result) {
  99.  
  100. if(err) {
  101. console.log('Error' + err + req.body);
  102. }
  103. else {
  104. res.status(200).send('Done');
  105. }
  106.  
  107. });
  108. });
Add Comment
Please, Sign In to add comment