Page 1 of 1
Newb Syntax error
Posted: Tue Oct 06, 2009 4:11 pm
by MiniMonty
Hi all,
I'm a big newb and trying to do cool things with php is turning out to be a lot of fun.
I'm getting an unexpected T Variable error and I'm 99% sure it's just a simple syntax error on my behalf.
I'm trying to refer to one of a number of .txt files each stored in a separate dir.
The user chooses via an html drop down list/menu named "gowhere" then hits the Submit button.
I think my error is in the path to the .txt file - I'm using this
Code: Select all
$myFile = "/images/gallery/"$_POST['gowhere']"/test.txt";
All and any help much appreciated
Best wishes
Monty
Re: Newb Syntax error
Posted: Tue Oct 06, 2009 4:23 pm
by deejay
try
Code: Select all
$myFile = "/images/gallery/".$_POST['gowhere']."/test.txt";
or
Code: Select all
$gowhere = $_POST['gowhere'];
$myFile = "/images/gallery/$gowhere/test.txt";
Re: Newb Syntax error
Posted: Wed Oct 07, 2009 5:50 am
by jackpf
Yeah..deejay got it. Just to elaborate, it's called concatenation.
http://www.w3schools.com/PHP/php_string.asp
For more info

Re: Newb Syntax error
Posted: Wed Oct 07, 2009 6:32 am
by MiniMonty
Works good for $myFile = but the array doesn't like it
This line gives a T_String error...
Code: Select all
$array = glob('/images/gallery/.$_POST['gowhere']/*');
Re: Newb Syntax error
Posted: Wed Oct 07, 2009 6:53 am
by MiniMonty
Solved the array thing but I now get this:
Warning: fopen(/images/gallery//gallarray.txt) [function.fopen]: failed to open stream: No such file or directory in blah blah blah
the double slash would suggest that the variable is not being concantenated into the string.
Re: Newb Syntax error
Posted: Wed Oct 07, 2009 7:21 am
by jackpf
What's your current code?
Re: Newb Syntax error
Posted: Wed Oct 07, 2009 7:31 am
by Eric!
MiniMonty wrote:Works good for $myFile = but the array doesn't like it
This line gives a T_String error...
Code: Select all
$array = glob('/images/gallery/.$_POST['gowhere']/*');
Your string concatenation isn't correct. Assuming your $_POST value isn't empty, try this instead:
Code: Select all
$array = glob('/images/gallery/'.$_POST['gowhere'].'/*');
or
Code: Select all
$mypath="/images/gallery/".$_POST['gowhere']."/*";
$array = glob($mypath);
Re: Newb Syntax error
Posted: Wed Oct 07, 2009 7:41 am
by jackpf
Or
Code: Select all
$array = glob("/images/gallery/{$_POST['gowhere']}/*");
Or
Code: Select all
$array = glob("/images/gallery/$_POST[gowhere]/*");
Should work
