Guest User

Untitled

a guest
Feb 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. app.post("/api/submit", urlencodedParser, (req, res) => {
  2. if (req.url == "/api/submit") {
  3. var form = new formidable.IncomingForm();
  4. form.parse(req, function(err, fields, files) {
  5. mv(files.fileUpload.path, "./uploads/" + files.fileUpload.name, function(
  6. err
  7. ) {
  8. if (err) console.log("Error while saving the file.");
  9. console.log("File succesfully saved.");
  10. });
  11. });
  12. }
  13. var post = {
  14. firstName: req.body.firstName,
  15. lastName: req.body.lastName,
  16. comment: req.body.comment,
  17. email: req.body.email,
  18. mastering: req.body.mastering,
  19. orderDate: req.body.orderDate,
  20. optCd: "",
  21. optVinyl: "",
  22. optItunes: "",
  23. optIsrc: "",
  24. fileName: req.body.fileUpload
  25. };
  26. req.body.optCd === "on" ? (post.optCd = "1") : (post.optCd = "0");
  27. req.body.optVinyl === "on" ? (post.optVinyl = "1") : (post.optVinyl = "0");
  28. req.body.optItunes === "on" ? (post.optItunes = "1") : (post.optItunes = "0");
  29. req.body.optIsrc === "on" ? (post.optIsrc = "1") : (post.optIsrc = "0");
  30.  
  31. con.query("INSERT INTO orders SET?", post, function(err, result) {
  32. if (err) throw err;
  33. console.log("1 record inserted");
  34. });
  35. });
Add Comment
Please, Sign In to add comment