Jump to content

Concatenation problem


geroido

Recommended Posts

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

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

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.

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?

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?

$_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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.