geroido Posted July 18, 2008 Share Posted July 18, 2008 Hi I have a session variable that contains a string sent over from a form on the previous page. I want to concatenate another string onto the end of it. For example, the session variable holds a word like 'Galway' and I want to concatenate the string '.PHP' onto the end of it so I can include the file Galway.php on the page. I get the variable from the form with the following code: $_SESSION['town'] = $_GET['t']; Now onto the session variable 'town' I need to concatenate the string '.PHP'. Any ideas? Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/ Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 $town = $_SESSION['town'].".php"; include($town); Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593395 Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Hi Thanks for that but it's still not working. I'm printing the variable to see what it contains and all I'm getting is '.php'. The session variable itself is not printing so it's not being concatenated. I have the follwing code: $_SESSION['town'] = $_GET['t']; $townjoin = $_SESSION['town'].".php"; <H2 align="center"><?print $townjoin?></H2><BR> So all I get on the webpage is .php Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593400 Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Are you sure that $_GET['t'] has a value? Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593401 Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Yes I'm sure because I'm printing that value as well and it's appearing seperately on the webpage. I'm using the following code to do that: <H2 align="center"><?print $_SESSION['town']?></H2><BR> So I know I have the two values but they don't seem to be cocatenating. Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593407 Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Can you show us more code? Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593419 Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Hi I changed the just to test it and assign the session variable only to the new variable as in $townjoin = $_SESSION['town']; When I print $townjoin this time it's empty so there must be something wrong with assigning a session variable like this. Some small code error I suppose. Any ideas? Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593421 Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Hi I changed the just to test it and assign the session variable only to the new variable as in $townjoin = $_SESSION['town']; When I print $townjoin this time it's empty so there must be something wrong with assigning a session variable like this. Some small code error I suppose. Any ideas? Are you calling session_start() at the beginning of your code? Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593425 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Make sure session_start() is at the top of every single page. Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593426 Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 $_SESSION['town'] = $_GET['t']; $townjoin = $_SESSION['town'].".php"; <H2 align="center"><?print $_SESSION['town']?></H2><BR> <H2 align="center"><?print $townjoin?></H2><BR> This is the code. I get the string from the form ($_GET['t']) and I assign it to the session variable. This works because when I print the session variable it appears on the web page. However when I try to concatenate that onto '.php' and store the result in $townjoin all that prints is '.php'. Don't know what's wrong Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593428 Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Yes I'm calling session_start; at the top Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593430 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Why do you need to store it in a session? Why not use it straight from $_GET? $townjoin = $_GET['t'].".php"; Link to comment https://forums.phpfreaks.com/topic/115429-concatenation-problem/#findComment-593441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.