Jump to content

unexpected t_if


garyblackpool
 Share

Recommended Posts

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

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

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'; Edited by jkloth
Link to comment
Share on other sites

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

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

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. Edited by jkloth
Link to comment
Share on other sites

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

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

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

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

"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. :) Edited by jkloth
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...