garyblackpool Posted April 9, 2010 Share Posted April 9, 2010 Hi,I am using a query string to include files. But the function is not working its gives me the error:Parse error: syntax error, unexpected T_IFI am not sure what I am doing wrong so any help would be great.Thanks <?php $files = "include/more/" //check for the two varibles if ( isset ( $_GET['f'] == 'more' && $_GET['p'])){ if (file_exists($files . $_GET['p'] . '.php')){ $files . $_GET['p'] . '.php'; }else { $files .default.php; } } include $files ; ?> Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 Unexpected tokens usually result from missing semicolons. Look at the end of your first line of code.You may also have a problem with this line:$files .default.php; Link to comment Share on other sites More sharing options...
garyblackpool Posted April 9, 2010 Author Share Posted April 9, 2010 Unexpected tokens usually result from missing semicolons. Look at the end of your first line of code.You may also have a problem with this line:$files .default.php;Thanks for the fast reply. It was the missing semicolon. now got missing T_IS_EQUAL.erm could you point out, whats up with: $files .default.php;cheers all the help Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 Thanks for the fast reply. It was the missing semicolon. now got missing T_IS_EQUAL.You have misplaced parens () on this line:if ( isset ( $_GET['f'] == 'more' && $_GET['p'])){erm could you point out, whats up with: $files .default.php;For starters you're missing your quotes: $files .'default.php'I think this line also has the same issue:$files . $_GET['p'] . '.php';Are you trying to assign a value to $files?If so you would do this:$files = $_GET['p'] . '.php';If you're trying to concatenate a value onto $files it would be more like this:$files .= $_GET['p'] . '.php'; Link to comment Share on other sites More sharing options...
garyblackpool Posted April 9, 2010 Author Share Posted April 9, 2010 Okay cheers.This is what i have got so far. and receiving missing unexpected T_IS_EQUAL.Thanks. <?php $files = "include/more/" ; //check for the two varibles if ( isset ( $_GET['f'] == 'more') && isset($_GET['p'])){ if (file_exists($files . $_GET['p'] . '.php')){ $files . $_GET['p'] . '.php'; }else { $files .default.php ; } } include $files ; ?> Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 You still have misplaced parens. Particularly with this piece:isset ( $_GET['f'] == 'more')You need to break that out into two separate tests. You can't have the '==' inside the parens for the isset function. Link to comment Share on other sites More sharing options...
garyblackpool Posted April 9, 2010 Author Share Posted April 9, 2010 Thanks loads,got it working. Shame the include path isn't lol. Its nothing to do with the code is it?Thanks for all your help <?php $files = "more/" ; //check for the two varibles if ( ($_GET['f'] == 'more') && ($_GET['p'])){ if (file_exists($files . $_GET['p'] . '.php')){ $files . $_GET['p'] . '.php'; }else { $files .home.php ; } } include $files ; ?> Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 Shame the include path isn't lol. Its nothing to do with the code is it?See my previous post:For starters you're missing your quotes: $files .'default.php'I think this line also has the same issue:$files . $_GET['p'] . '.php';Are you trying to assign a value to $files?If so you would do this:$files = $_GET['p'] . '.php';If you're trying to concatenate a value onto $files it would be more like this:$files .= $_GET['p'] . '.php';Also the line...include $files ;...has incorrect syntax. You need parens. include is a function call so it should be like this: include($files);EDIT:BTW, what I was getting at with your if statement was this:if ( isset ( $_GET['f']) && ( $_GET['f'] == 'more') && isset($_GET['p'])){With the way you have it, if $_GET['f'] doesn't exist it will throw an error. If $_GET[f'] will always exist your way is fine. Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 Man, I must sound like Mr. Negative today. include is a language construct and does not require parens. However, parens are not wrong, and jkloth's statement will execute. Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 Man, I must sound like Mr. Negative today. include is a language construct and does not require parens. However, parens are not wrong, and jkloth's statement will execute.Well, I guess I stand corrected. Shows how much I really know about PHP. But that's why your here DD. Link to comment Share on other sites More sharing options...
garyblackpool Posted April 9, 2010 Author Share Posted April 9, 2010 Okay I think that I have done all the corrections. I have tried to echo the variable however the string concentration has not worked, and the $files only has "more/" assigned to it. Is this something to do with scope or am I still doing it wrong?Thanks again. <?php $files .= "more/" ; //check for the two varibles if ( ($_GET['f'] == 'more') && ($_GET['p'])){ if (file_exists($files .= $_GET['p'] . '.php')){ $files .= $_GET['p'] .'.php'; }else { $files .= 'home.php' ; } } include ($files) ; echo "$files" ; ?> Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 PHP variables are available everywhere inside a function. And every variable used in the global space is available everywhere in the global space.I would assume that your first if-test is failing. Try var_dump ($_GET) at the top of your script to see what's actually in there. Link to comment Share on other sites More sharing options...
thescientist Posted April 9, 2010 Share Posted April 9, 2010 Well, I guess I stand corrected. Shows how much I really know about PHP. But that's why your here DebbieDowner? Link to comment Share on other sites More sharing options...
jeffman Posted April 9, 2010 Share Posted April 9, 2010 "I came for the waters.""There are no waters in Casablanca.""I was misinformed." Link to comment Share on other sites More sharing options...
ShadowMage Posted April 9, 2010 Share Posted April 9, 2010 "I came for the waters.""There are no waters in Casablanca.""I was misinformed." Anyway, is this the first time you assign a value to $files:$files .= "more/" ;If so you don't need to use the '.=' you can just use '='In fact I think it's supposed to throw an error if you use '.=' the when you initialize a variable. But then again I've been proven wrong before. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.