androsgoh Posted January 4, 2016 Share Posted January 4, 2016 Hi, I have problem with this error : Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in .. line 23. I knew is something to do with the syntax but just couldn't get a hand on it where is the problem ? Appreciate any help. Thank you. Androsgoh phpcode.txt Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2016 Share Posted January 4, 2016 1. Just post code normally. With the code highlighting. Most people don't bother looking at attachments. 2. Don't post database credentials. Stop what you're doing and go change your password. Right now. $query =" //set NOCOUNT ON /*optional*/ SELECT cast(h1.Weeknum AS varchar) +'|' +cast(h1.Year AS varchar) +'|' +QUOTENAME(CASE WHEN Cty.CountryName = 'Singapore' THEN 'SG' WHEN Cty.CountryName = 'Hong Kong' THEN 'HK' WHEN Cty.CountryName = 'Japan' THEN 'JP' WHEN Cty.CountryName = 'China' THEN 'CN' WHEN Cty.CountryName = 'Indonesia' THEN 'ID' WHEN Cty.CountryName = 'Taiwan' THEN 'TW' WHEN Cty.CountryName = 'Thailand' THEN 'TH' WHEN Cty.CountryName = 'Philippines' THEN 'PH' WHEN Cty.CountryName = 'Macau' THEN 'MO' WHEN Cty.CountryName = 'Malaysia' THEN 'MY' ELSE '' END , '""') +'|' + QUOTENAME(Loc.LocationName,'"') +'|' +QUOTENAME(CASE WHEN Cust.CustomerName = 'McDonalds'THEN'MCD' WHEN Cust.CustomerName = 'Subway' THEN 'SWY' WHEN Cust.CustomerName = 'Oishi' THEN 'OIS' WHEN Cust.CustomerName = 'Shell' THEN 'SHE' WHEN Cust.CustomerName = 'FSB' THEN 'FSB' WHEN Cust.CustomerName = 'Ikea' THEN 'IKE' WHEN Cust.CustomerName = 'Yellow Cab' THEN 'YEL' WHEN Cust.CustomerName = 'PUB' THEN 'PUB' ELSE '' END, '""') +'|'+cast(round(k1.[Value], 0) as varchar) +'|'+'0' -- Tonnage Delivered, assume 0 for now +'|'+cast(k2.[VALUE] as varchar) +'|'+cast(k3.[VALUE] as varchar) +'|'+cast(k4.[VALUE] as varchar) +'|'+'0' -- Deliveries with error, assume 0 for now +'|'+cast(k5.[VALUE] as varchar) +'|'+cast((round(k9.[VALUE]+k1.[VALUE],0)) as varchar) +'|'+cast(round(k7.[VALUE],0) as varchar) +'|'+'0' -- Tonnage Handled, assume 0 for now +'|'+cast(round(k8.[VALUE],0) as varchar) +'|'+'20151130' +'|'+'20151206' FROM [KeyPerformance].[dbo].[KpiDetails] as k1, [KeyPerformance].[dbo].[KpiDetails] as k2, [KeyPerformance].[dbo].[KpiDetails] as k3, [KeyPerformance].[dbo].[KpiDetails] as k4, [KeyPerformance].[dbo].[KpiDetails] as k5, [KeyPerformance].[dbo].[KpiDetails] as k6, [KeyPerformance].[dbo].[KpiDetails] as k7, [KeyPerformance].[dbo].[KpiDetails] as k8, [KeyPerformance].[dbo].[KpiDetails] as k9, [KeyPerformance].[dbo].[KpiHeader] as h1, [KeyPerformance].[dbo].[Customer] as Cust, [KeyPerformance].[dbo].[Location] as Loc, [KeyPerformance].[dbo].[Country] as Cty, [KeyPerformance].[dbo].[CalendarWeekOfYear] as Cal where k1.[KpiHeaderID] = k2.[KpiHeaderID] AND k2.[KpiHeaderID] = k3.[KpiHeaderID] AND k3.[KpiHeaderID] = k4.[KpiHeaderID] AND k4.[KpiHeaderID] = k5.[KpiHeaderID] AND k5.[KpiHeaderID] = k6.[KpiHeaderID] AND k6.[KpiHeaderID] = k7.[KpiHeaderID] AND k7.[KpiHeaderID] = k8.[KpiHeaderID] AND k8.[KpiHeaderID] = k9.[KpiHeaderID] AND k1.[KpiHeaderID] = h1.[KpiHeaderID] AND h1.[CustomerID] = Cust.[CustomerID] AND h1.[LocationID] = Loc.[LocationID] AND Loc.[CountryID] = Cty.[CountryID] AND h1.[WeekNum] = Cal.WeekOfYear AND h1.[Year] = Cal.Year -- AND k1.[KpiHeaderID] = 122 AND k1.[KpiItemsID] = 2 AND k2.[KpiItemsID] = 1 AND k3.[KpiItemsID] = 9 AND k4.[KpiItemsID] = 10 AND k5.[KpiItemsID] = 31 AND k6.[KpiItemsID] = 2 AND k7.[KpiItemsID] = 18 AND k8.[KpiItemsID] = 11 AND k9.[KpiItemsID] = 3 AND h1.Year = '2015' and Cal.WeekofYear = 48 --AND Cal.MonthID = 11;"You have unescaped "s within that string. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 4, 2016 Share Posted January 4, 2016 when doing large/multiline blocks of text like that, consider using heredoc or nowdoc to help avoid this issue. Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 4, 2016 Share Posted January 4, 2016 (edited) *Edit: Confused answer with the makePass function. Edited January 4, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2016 Share Posted January 4, 2016 (edited) *Edit: Confused answer with the makePass function.What? $query = <<<SQL //set NOCOUNT ON /*optional*/ SELECT cast(h1.Weeknum AS varchar) +'|' +cast(h1.Year AS varchar) +'|' +QUOTENAME(CASE WHEN Cty.CountryName = 'Singapore' THEN 'SG' WHEN Cty.CountryName = 'Hong Kong' THEN 'HK' WHEN Cty.CountryName = 'Japan' THEN 'JP' WHEN Cty.CountryName = 'China' THEN 'CN' WHEN Cty.CountryName = 'Indonesia' THEN 'ID' WHEN Cty.CountryName = 'Taiwan' THEN 'TW' WHEN Cty.CountryName = 'Thailand' THEN 'TH' WHEN Cty.CountryName = 'Philippines' THEN 'PH' WHEN Cty.CountryName = 'Macau' THEN 'MO' WHEN Cty.CountryName = 'Malaysia' THEN 'MY' ELSE '' END , '""') +'|' + QUOTENAME(Loc.LocationName,'"') +'|' +QUOTENAME(CASE WHEN Cust.CustomerName = 'McDonalds'THEN'MCD' WHEN Cust.CustomerName = 'Subway' THEN 'SWY' WHEN Cust.CustomerName = 'Oishi' THEN 'OIS' WHEN Cust.CustomerName = 'Shell' THEN 'SHE' WHEN Cust.CustomerName = 'FSB' THEN 'FSB' WHEN Cust.CustomerName = 'Ikea' THEN 'IKE' WHEN Cust.CustomerName = 'Yellow Cab' THEN 'YEL' WHEN Cust.CustomerName = 'PUB' THEN 'PUB' ELSE '' END, '""') +'|'+cast(round(k1.[Value], 0) as varchar) +'|'+'0' -- Tonnage Delivered, assume 0 for now +'|'+cast(k2.[VALUE] as varchar) +'|'+cast(k3.[VALUE] as varchar) +'|'+cast(k4.[VALUE] as varchar) +'|'+'0' -- Deliveries with error, assume 0 for now +'|'+cast(k5.[VALUE] as varchar) +'|'+cast((round(k9.[VALUE]+k1.[VALUE],0)) as varchar) +'|'+cast(round(k7.[VALUE],0) as varchar) +'|'+'0' -- Tonnage Handled, assume 0 for now +'|'+cast(round(k8.[VALUE],0) as varchar) +'|'+'20151130' +'|'+'20151206' FROM [KeyPerformance].[dbo].[KpiDetails] as k1, [KeyPerformance].[dbo].[KpiDetails] as k2, [KeyPerformance].[dbo].[KpiDetails] as k3, [KeyPerformance].[dbo].[KpiDetails] as k4, [KeyPerformance].[dbo].[KpiDetails] as k5, [KeyPerformance].[dbo].[KpiDetails] as k6, [KeyPerformance].[dbo].[KpiDetails] as k7, [KeyPerformance].[dbo].[KpiDetails] as k8, [KeyPerformance].[dbo].[KpiDetails] as k9, [KeyPerformance].[dbo].[KpiHeader] as h1, [KeyPerformance].[dbo].[Customer] as Cust, [KeyPerformance].[dbo].[Location] as Loc, [KeyPerformance].[dbo].[Country] as Cty, [KeyPerformance].[dbo].[CalendarWeekOfYear] as Cal where k1.[KpiHeaderID] = k2.[KpiHeaderID] AND k2.[KpiHeaderID] = k3.[KpiHeaderID] AND k3.[KpiHeaderID] = k4.[KpiHeaderID] AND k4.[KpiHeaderID] = k5.[KpiHeaderID] AND k5.[KpiHeaderID] = k6.[KpiHeaderID] AND k6.[KpiHeaderID] = k7.[KpiHeaderID] AND k7.[KpiHeaderID] = k8.[KpiHeaderID] AND k8.[KpiHeaderID] = k9.[KpiHeaderID] AND k1.[KpiHeaderID] = h1.[KpiHeaderID] AND h1.[CustomerID] = Cust.[CustomerID] AND h1.[LocationID] = Loc.[LocationID] AND Loc.[CountryID] = Cty.[CountryID] AND h1.[WeekNum] = Cal.WeekOfYear AND h1.[Year] = Cal.Year -- AND k1.[KpiHeaderID] = 122 AND k1.[KpiItemsID] = 2 AND k2.[KpiItemsID] = 1 AND k3.[KpiItemsID] = 9 AND k4.[KpiItemsID] = 10 AND k5.[KpiItemsID] = 31 AND k6.[KpiItemsID] = 2 AND k7.[KpiItemsID] = 18 AND k8.[KpiItemsID] = 11 AND k9.[KpiItemsID] = 3 AND h1.Year = '2015' and Cal.WeekofYear = 48 --AND Cal.MonthID = 11; SQL;(huh. okay. pretend there's appropriate highlighting) Doing that would have completely bypassed the quotes problem. Edited January 4, 2016 by requinix Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 4, 2016 Share Posted January 4, 2016 (edited) You posted before I deleted it. I got confused seeing the makepass function in his post which appears to have nothing whatsoever to do with this thread. Edited January 4, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.