james909 Posted February 19, 2013 Share Posted February 19, 2013 (edited) 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? Edited February 19, 2013 by james909 Quote 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. Quote 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 Quote 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 Quote 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 (edited) 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> Edited February 19, 2013 by pmccall2 Quote 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? Quote 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 (edited) 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 Edited February 19, 2013 by james909 Quote 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?? Quote 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 (edited) 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' Edited February 19, 2013 by james909 Quote 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 (edited) Is that a nested if/else in the OP? If so I believe you're missing a closing brace ( } ). I only see one Edited February 19, 2013 by TOA Quote 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 Quote 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... Quote 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 Quote 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? Quote 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 (edited) 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()) Edited February 19, 2013 by TOA Quote 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: Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.