Newb Syntax error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Newb Syntax error

Post 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
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: Newb Syntax error

Post 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";
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb Syntax error

Post by jackpf »

Yeah..deejay got it. Just to elaborate, it's called concatenation.

http://www.w3schools.com/PHP/php_string.asp

For more info :)
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb Syntax error

Post 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']/*');
 
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb Syntax error

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb Syntax error

Post by jackpf »

What's your current code?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Newb Syntax error

Post 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);
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb Syntax error

Post by jackpf »

Or

Code: Select all

$array = glob("/images/gallery/{$_POST['gowhere']}/*");
Or

Code: Select all

$array = glob("/images/gallery/$_POST[gowhere]/*");
Should work :)
Post Reply