guymclaren272 Posted February 2, 2013 Share Posted February 2, 2013 If ($Hoff == 'Nelspruit') || ($Hoff == 'Hoedspruit') || ($Hoff == 'Klaserie') || ($Hoff == 'Bushbuck Ridge') || ($Hoff == 'Hazyview') || ($Hoff == 'Graskop') OR ($Hoff == 'Sabie') || ($Hoff == 'Lydenburg') || ($Hoff == 'Pilgrims Rest') || ($Hoff == 'Barberton') || ($Hoff == 'Waterval Boven') || ($Hoff == 'Komatipoort') || ($Hoff == 'Malelane') { $addon = $addon +2; } else { $addon = $addon -100; } PHP Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in /home/lowveldn/public_html/control/publish.php on line 84 Can someone tell me what is wrong here please. Link to comment https://forums.phpfreaks.com/topic/273943-if-or-statement-fail/ Share on other sites More sharing options...
Psycho Posted February 2, 2013 Share Posted February 2, 2013 All of your conditions must be contained within a single set of parens (but you may have sub-parens inside) E.g. if ($Hoff == 'Nelspruit' || $Hoff == 'Hoedspruit' || $Hoff == 'Klaserie' || $Hoff == 'Bushbuck Ridge' || $Hoff == 'Hazyview' || $Hoff == 'Graskop' || $Hoff == 'Sabie' || $Hoff == 'Lydenburg' || $Hoff == 'Pilgrims Rest' || $Hoff == 'Barberton' || $Hoff == 'Waterval Boven' || $Hoff == 'Komatipoort' || $Hoff == 'Malelane') { $addon = $addon +2; } else { $addon = $addon -100; } Or if ( ($Hoff == 'Nelspruit') || ($Hoff == 'Hoedspruit') || ($Hoff == 'Klaserie') || ($Hoff == 'Bushbuck Ridge') || ($Hoff == 'Hazyview') || ($Hoff == 'Graskop') || ($Hoff == 'Sabie') || ($Hoff == 'Lydenburg') || ($Hoff == 'Pilgrims Rest') || ($Hoff == 'Barberton') || ($Hoff == 'Waterval Boven') || ($Hoff == 'Komatipoort') || ($Hoff == 'Malelane') ) { $addon = $addon +2; } else { $addon = $addon -100; } But, a much better way to handle this is by using an array. You can replace all of the above code with just this $hoffList = array( 'Nelspruit', 'Hoedspruit', 'Klaserie', 'Bushbuck Ridge', 'Hazyview', 'Graskop', 'Sabie', 'Lydenburg', 'Pilgrims Rest', 'Barberton', 'Waterval Boven', 'Komatipoort', 'Malelane' ); $addon += (in_array($Hoff, $hoffList)) ? 2 : -100; Link to comment https://forums.phpfreaks.com/topic/273943-if-or-statement-fail/#findComment-1409679 Share on other sites More sharing options...
codebyren Posted February 2, 2013 Share Posted February 2, 2013 Your entire IF statement needs to be within Parentheses (brackets). So, something like: if ($Hoff == 'Nelspruit' || $Hoff == 'Hoedspruit' || $Hoff == 'Klaserie' || $Hoff == 'Whatever else') { $addon = $addon+2; } else { $addon = $addon -100; } Should do the trick... Link to comment https://forums.phpfreaks.com/topic/273943-if-or-statement-fail/#findComment-1409680 Share on other sites More sharing options...
TuQuoQueBrute Posted February 2, 2013 Share Posted February 2, 2013 Link to comment https://forums.phpfreaks.com/topic/273943-if-or-statement-fail/#findComment-1409681 Share on other sites More sharing options...
guymclaren272 Posted February 2, 2013 Author Share Posted February 2, 2013 Thank you all, Do I feel like a total idiot about right now. Help appreciated and Psyco thanks for the alternative, I will definitely try that Link to comment https://forums.phpfreaks.com/topic/273943-if-or-statement-fail/#findComment-1409682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.