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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

$_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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.