требует объявить переменную из кук, в чем проблема?
Cannot read property 'vprodaj' of undefined
at C:\xampp\htdocs\mysite2.local\app.js:179:16 at Layer.handle [as handle_request] (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\layer.js:95:5) at next (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\route.js:137:13) at Route.dispatch (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\layer.js:95:5) at C:\xampp\htdocs\mysite2.local\node_modules\express \lib\router\index.js:281:22 at Function.process_params (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\index.js:335:12) at next (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\index.js:275:10) at C:\xampp\htdocs\mysite2.local\node_modules\express-fileupload\lib\index.js:34:14 at Layer.handle [as handle_request] (C:\xampp\htdocs\mysite2.local\node_modules\expres s\lib\router\layer.js:95:5) var express = require('express'); var mysql = require('mysql'); const fileUpload = require('express-fileupload'); var app = express(); const bodyParser = require("body-parser"); cookies = require('cookie-parser'); app.use(fileUpload()); /// /// Create connection to MySQL database server. /// function getMySQLConnection() { return mysql.createConnection({ host : 'localhost', user : 'mysql', password : 'mysql', database : 'elektronika' }); } app.set('view engine', 'ejs'); /// app.get('/smart', function(req, res) { var prmin,prmax; var smartphopneList = []; // Connect to MySQL database. var connection = getMySQLConnection(); // Do the query to get data. // Render index.pug page using array var otherwhere=''; if(req.cookies.vprodaj=='checked'){ otherwhere=otherwhere+' AND WHERE count>0 '; } if(req.cookies.soskidkoi=='checked'){ otherwhere=otherwhere+' AND WHERE (`price` -`price` / 100 * `sale`) >0 '; } if(req.cookies.dbesplat=='checked'){ otherwhere=otherwhere+' AND WHERE `dbesplat`=1 '; } if(req.cookies.promokodi=='checked'){ otherwhere=otherwhere+' AND WHERE `promokodi`=1 '; } if(req.cookies.presents=='checked'){ otherwhere=otherwhere+' AND WHERE `presents`=1 '; } if(req.cookies.newtov=='checked' ){ otherwhere=otherwhere+' AND WHERE `newtov`=1 '; } if(req.cookies.uctov=='checked'){ otherwhere=otherwhere+' AND WHERE `uctov`=1 '; } if(req.cookies.garantprod=='checked'){ otherwhere=otherwhere+' AND WHERE `soskidkoi`>0 '; } if(req.cookies.oswin=='checked'){ otherwhere=otherwhere+' AND WHERE `oswin`=1 '; } if(req.cookies.osios=='checked'){ otherwhere=otherwhere+' AND WHERE `osios`=1 '; } if(req.cookies.osandrod=='checked'){ otherwhere=otherwhere+' AND WHERE `checked`=1 '; } if(!otherwhere){ var where='WHERE (`price` -`price` / 100 * `sale`) >= '+7000+' AND (`price` -`price` / 100 * `sale`) <= '+20000; }else{ var where='WHERE (`price` -`price` / 100 * `sale`) >= '+7000+' AND (`price` -`price` / 100 * `sale`) <= '+20000 +otherwhere; } query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,`dbesplat`,`promokodi`,`presents`,`newtov`,`garantprod`,(`price` -`price` / 100 * `sale`) AS `tsale` FROM `smartphone` '+where+' ORDER BY '+order +' '+side;connection.query(query, function(err, rows, fields) { connection.connect(function(errr){ if (errr) { res.status(500).json({"status_code": 500,"status_message": "internal server error"}); console.log(err); } else { connection.query(sql3, [], function (err, rows) { // Loop check on each row var rowlenght=rows.length+1; for (var i = 0; i < rows.length; i++) { var smartphopne = { 'id':rows[i].id, 'prod':rows[i].prod, 'name':rows[i].name, 'photo':rows[i].photo, 'description':rows[i].description, 'price':rows[i].price, 'sale':rows[i].sale, 'len':rowlenght, 'tsale':rows[i].tsale, 'prmin':7000, 'prmax':20000, 'cprmin':req.cookies.prmin, 'cprmax':req.cookies.prmax, 'vprodaj':req.cookies.vprodaj, 'soskidkoi':req.cookies.soskidkoi, 'dbesplat':req.cookies.dbesplat, 'promokodi':req.cookies.promokodi, 'presents':req.cookies.presents, 'newtov':req.cookies.newtov, 'uctov':req.cookies.uctov, 'garantprod':req.cookies.garantprod, 'oswin':req.cookies.oswin, 'osios':req.cookies.osios, 'osandrod':req.cookies.osandrod, }; // Add object into array smartphopneList.push(smartphopne); } // Render index.pug page using array res.render('index', {"smartphopneList": smartphopneList}); }); } }); }); // Close the MySQL connection connection.end(); }); |
cookie-parser у тебя импортируется но не используется.
const cookies = require('cookie-parser'); app.use(cookies()) |
У вас запрос чутка неправильный собирается, примерно такой:
select * from table where 1 and where 2 and where 3 ps. Цитата:
var firsrtString = 'hello'; var secondString = 'hello'; firsrtString = firsrtString + ' world'; secondString += ' world'; alert(firsrtString === secondString); |
Часовой пояс GMT +3, время: 05:31. |