Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 30.11.2020, 19:39
Аспирант
Отправить личное сообщение для riaron Посмотреть профиль Найти все сообщения от riaron
 
Регистрация: 16.08.2020
Сообщений: 53

требует объявить переменную из кук, в чем проблема?
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();
});

Последний раз редактировалось riaron, 30.11.2020 в 19:54.
Ответить с цитированием
  #2 (permalink)  
Старый 01.12.2020, 04:56
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,491

cookie-parser у тебя импортируется но не используется.
const cookies = require('cookie-parser');
app.use(cookies())
__________________
29375, 35
Ответить с цитированием
  #3 (permalink)  
Старый 01.12.2020, 05:04
Профессор
Отправить личное сообщение для Nexus Посмотреть профиль Найти все сообщения от Nexus
 
Регистрация: 04.12.2012
Сообщений: 3,723

У вас запрос чутка неправильный собирается, примерно такой:
select * from table where 1 and where 2 and where 3


ps.
Сообщение от riaron
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 ';
}
var firsrtString = 'hello';
var secondString = 'hello';

firsrtString = firsrtString + ' world';
secondString += ' world';

alert(firsrtString === secondString);

Последний раз редактировалось Nexus, 01.12.2020 в 05:08.
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите. В чем проблема ? (toggle) brondex Events/DOM/Window 1 23.10.2011 18:48
В чем проблема с IE? lessless jQuery 1 19.07.2011 22:44
Ошибка в jQuery 1.5.1. Не понимаю в чем проблема? viatcheslav AJAX и COMET 0 16.05.2011 11:38
unterminated string literal - в чем проблема MaxB Общие вопросы Javascript 5 09.07.2010 12:20
В чем проблема? скрипт по удалению фото... :( yukazerg23 jQuery 2 29.04.2009 10:25