james909 Posted February 19, 2013 Share Posted February 19, 2013 Can someone tell me what the error is in this PHP '$_GET if else' code <!-- /debughtml --> </div> <br /> <?php if (isset($_GET['title']) && $_GET['title'] == 'Main_Page,Community_portal,Current_events,Special:RecentChanges,Help:Contents,Special:WhatLinksHere/Help:Contents,Special:Upload,Special:SpecialPages,itsmywiki.com:Privacy_policy,itsmywiki.com:About,itsmywiki:General_disclaimer,Special:Preferences,Special:Watchlist,Special:Contributions/itsmywiki.com,Special:UserLogout&returnto=Special%3AContributions%2F$,User:$,User_talk:$') { // do nothing } else { if (isset($_GET['action']) && $_GET['action'] == 'edit,history') { // do nothing } else { ?> <center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center> <?php } ?> <!-- /bodyContent --> this code is causing a syntax error further down the page, and i cant figure out what the problem is? Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/ Share on other sites More sharing options...
pmccall2 Posted February 19, 2013 Share Posted February 19, 2013 Probably has something to do with your php tags. If the second else statement is used you have 2 sets of end tags. Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413451 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 thank you for your reply pmccall2, what is the correct way to include html within php, i was unsure about that coding Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413454 Share on other sites More sharing options...
ultraloveninja Posted February 19, 2013 Share Posted February 19, 2013 You can use echo: http://php.net/manual/en/function.echo.php Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413456 Share on other sites More sharing options...
pmccall2 Posted February 19, 2013 Share Posted February 19, 2013 I usually try and separate the logic from the html. For the current code it would be something like. <?php //logic goes here if (isset($_GET['action']) && $_GET['action'] = "myaction") { $action = ""; } else { $action = "html string"; } ?> <div> <?php echo $action; ?> </div> Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413460 Share on other sites More sharing options...
AyKay47 Posted February 19, 2013 Share Posted February 19, 2013 What is the exact error that is being displayed? Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413466 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 thanks for all the help akkay47, it is showing "Parse error: syntax error, unexpected T_PRIVATE in /home/acc/public_html/itsmywiki.com/skins/Vector.php on line 268" in the web-browser i changed the html line using 'echo' to } else { echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>'; } ?> and it is still showing a syntax error Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413469 Share on other sites More sharing options...
Jessica Posted February 19, 2013 Share Posted February 19, 2013 What is line 268 (and the few around it) of file /home/acc/public_html/itsmywiki.com/skins/Vector.php?? Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413471 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 line 268 is a few lines after this code that i am editing, this error appeared when i first started adding this '$_GET if else code' Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413474 Share on other sites More sharing options...
TOA Posted February 19, 2013 Share Posted February 19, 2013 Is that a nested if/else in the OP? If so I believe you're missing a closing brace ( } ). I only see one Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413475 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 thank you TOA! it was the missing closing braket } the syntax error has gone away and the page loads the code that i wrote is still not working as it should the url 'http://itsmywiki.com/index.php?title=Main_Page' is displaying the facebook comment code, and i am trying to use the title variable in the the if code to avoid the Main_Page (along with the other pages) displaying the facebook comments Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413476 Share on other sites More sharing options...
TOA Posted February 19, 2013 Share Posted February 19, 2013 Most likely, your desired titles and actions are being treated as strings; that's what it looks like to me. You either need to test for each one, or make an array out of the values and use in_array. Ex: $allowed = array('edit','history'); if (in_array($_GET['action'], $allowed)) { // show comment code } Something like that... Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413477 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 thank you for the reply TOA, i have changed the code to: <!-- /debughtml --> </div> <br /> <?php $allowed = array('Main_Page','Community_portal','Current_events','Special:RecentChanges','Help:Contents','Special:WhatLinksHere/Help:Contents','Special:Upload,Special:SpecialPages','itsmywiki.com:Privacy_policy','itsmywiki.com:About','itsmywiki:General_disclaimer','Special:Preferences,Special:Watchlist','Special:Contributions/itsmywiki.com','Special:UserLogout&returnto=Special%3AContributions%2F$','User:$,User_talk:$'); if (in_array($_GET['action'], $allowed)) { // do nothing } else { $allowed = array('edit','history'); if (in_array($_GET['action'], $allowed)) { // do nothing } else { echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>'; } }?> <!-- /bodyContent --> and the facebook comments is still appearing on all the URLs :confused: example of the URLs: http://itsmywiki.com/index.php?title=Page_1 (i want the facebook comments to appear here) http://itsmywiki.com/index.php?title=Page_1&action=edit (i dont want the facebook comments to appear here) http://itsmywiki/index.php?title=Main_Page (i dont want the facebook comments to appear here) but the facebook comments is currently appearing on every site page Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413482 Share on other sites More sharing options...
TOA Posted February 19, 2013 Share Posted February 19, 2013 Your OP checked both $_GET['title'] and $_GET['action']. In this most recent version, you check action in both cases. Was that an intentional change? Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413483 Share on other sites More sharing options...
TOA Posted February 19, 2013 Share Posted February 19, 2013 Also, check out this indented version $banned = array('Main_Page','Community_portal','Current_events','Special:RecentChanges','Help:Contents','Special:WhatLinksHere/Help:Contents','Special:Upload,Special:SpecialPages','itsmywiki.com:Privacy_policy','itsmywiki.com:About','itsmywiki:General_disclaimer','Special:Preferences,Special:Watchlist','Special:Contributions/itsmywiki.com','Special:UserLogout&returnto=Special%3AContributions%2F$','User:$,User_talk:$'); $allowed = array('edit','history'); if (in_array($_GET['title'], $banned)) { // do nothing } else { if (in_array($_GET['action'], $allowed)) { // do nothing } else { echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>'; } } if the $_GET['title'] is in that array, you do nothing. Try negating that (!in_array()) Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413484 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 thank you so much TOA and everyone else that helped! i like that '$banned = array' it makes it very easy to add to :happy-04: Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413492 Share on other sites More sharing options...
james909 Posted February 19, 2013 Author Share Posted February 19, 2013 a further question, what is the command for any text, like the '*' in google and file searches so that pages with: title=User_talk:joe_bloggs title=User_talk:tom title=User_talk:dick title=User_talk:harry are all covered i tried 'User_talk*' and 'User_talk$' and didnt work Link to comment https://forums.phpfreaks.com/topic/274693-can-someone-tell-me-what-the-error-is-in-this-php-_get-if-else-code/#findComment-1413495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.