adamriley Posted December 22, 2009 Share Posted December 22, 2009 Hi my php code is -------------------------------------------------------------- <?php if (isset($_GET['a']) && $_GET['a'] != "") { if (isset($_GET['b']) && $_GET['b'] != "") { $a = $_GET['a']; $b = $_GET['b']; if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } elseif (!file_exists('pages/'.$a.'.$b')) { echo 'Page you are requesting doesnt exist'; } } else { @include ('pages/1.php'); } ?> --------------------------------------------- my url is "sitemap.php?a=1&b=php" -------------------------------------------- could you say why its not working im a beginner Quote Link to comment Share on other sites More sharing options...
sh0wtym3 Posted December 22, 2009 Share Posted December 22, 2009 What error are you getting? And if you don't see any errors just add: error_reporting(E_ALL); ... to the top of your code. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 22, 2009 Share Posted December 22, 2009 for us to help you, you will have to elaborate on whats not working, you must tell us 1) Whats the result 2) What was the expected result Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Are you getting any errors? put this at the top of your script.. error_reporting(E_ALL); ini_set('display_errors',1); And remove the @ symbols.. Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 ok what i get is "Parse error: syntax error, unexpected $end in /home/a162162/public_html/sitemap.php on line 47" what i expected is the file that was named in the "a=1" and the file format that was "b=php" Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 you are missing a } at the end of your script.. formatting helps find these things out <?php if (isset($_GET['a']) && $_GET['a'] != "") { if (isset($_GET['b']) && $_GET['b'] != "") { $a = $_GET['a']; $b = $_GET['b']; if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } elseif (!file_exists('pages/'.$a.'.$b')) { echo 'Page you are requesting doesnt exist'; } } else { @include ('pages/1.php'); } } ?> Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 This part of the script is now solved but now it seems that it cannot find the page when i try the script with 1 parameter. The script excludes the "Page you are requesting doesnt exist" Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 This part of the script is now solved but now it seems that it cannot find the page when i try the script with 1 parameter. The script excludes the "Page you are requesting doesnt exist" Sorry that one is very confusing what i ment is that bit of the script now works but the script now says "Page you are requesting doesnt exist" Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 You need to simplify the code down a bit.. if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } elseif (!file_exists('pages/'.$a.'.$b')) { echo 'Page you are requesting doesnt exist'; } can be simply put as if (file_exists('pages/'.$a.'.$b')) { @include ('pages/'.$a.'.$b'); } else { echo 'Page you are requesting doesnt exist'; } because you already know the page doesnt exist... Here is a cleaner version.. <?php if (isset($_GET['a']) && isset($_GET['b']) && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (file_exists('pages/'.$a.'.$b')) { include('pages/'.$a.'.$b'); } else { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Make sure that your directory structure matches what you are testing for.. Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 Hi thanks my directory structure matches what you i am testing for and the script still does not dissplay what i want it to Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 You could infact ignore that file_exists.. <?php if (isset($_GET['a']) && isset($_GET['b']) && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (!@include('pages/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Edit: I just noticed an error which is gone in the code above 'pages/'.$a.'.$b' would be looking for 1.$b Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 The script still does not work :confused: Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Did you use the last edited version I posted? <?php if (isset($_GET['a']) && isset($_GET['b']) && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (!@include('pages/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 Ok thanks the script does now work which part of the script did you change Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Just 'pages/'.$a.'.$b' to 'pages/'.$a.'.'.$b Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 22, 2009 Author Share Posted December 22, 2009 so if i was to add a third parameter what would i need to add Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 What will the 3rd parameter be for? Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 If i was to add a c parameter to the bit that says "('pages/" and put $c what would the script now be Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 so $c would replace the word pages? Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 yes it would so the url would be something like sitemap.php?a=1&b=php&c=pages Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 then it would be <?php if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') { $a = $_GET['a']; $b = $_GET['b']; if (!@include($c.'/'.$a.'.'.$b)) { echo 'Page you are requesting doesnt exist'; } } else { include ('pages/1.php'); } ?> Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Thanks very much for your time Buddski Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 Not a problem.. Quote Link to comment Share on other sites More sharing options...
adamriley Posted December 23, 2009 Author Share Posted December 23, 2009 Am i right in thinking you missed "$c = $_GET['c'];" from the script Quote Link to comment Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 Indeed you are 5am coding is never good.. 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.