Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-30-2012, 02:57 AM   PM User | #1
Eggweezer
New Coder

 
Join Date: May 2012
Posts: 97
Thanks: 75
Thanked 0 Times in 0 Posts
Eggweezer is an unknown quantity at this point
Problem using a variable with re-direct header location.....

I am trying to use a variable in my re-direct, and cannot get it to work.

My original code was:
PHP Code:
header("Location: view_trail_gallery_images.php"); 
BUT, I am trying to replace the words trail_gallery with a variable called $galleryName
I have made numerous attempts which included .....
PHP Code:
header("Location: view_$galleryName_images.php"); 
I would appreciate any help. Thanks!
Eggweezer is offline   Reply With Quote
Old 12-30-2012, 03:47 AM   PM User | #2
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
Quote:
Originally Posted by Eggweezer View Post
I am trying to use a variable in my re-direct, and cannot get it to work.

My original code was:
PHP Code:
header("Location: view_trail_gallery_images.php"); 
BUT, I am trying to replace the words trail_gallery with a variable called $galleryName
I have made numerous attempts which included .....
PHP Code:
header("Location: view_$galleryName_images.php"); 
I would appreciate any help. Thanks!


Try:
PHP Code:
header("Location: view_'.$galleryName.'_images.php"); 
tempz is offline   Reply With Quote
Users who have thanked tempz for this post:
Eggweezer (12-30-2012)
Old 12-30-2012, 03:57 AM   PM User | #3
Eggweezer
New Coder

 
Join Date: May 2012
Posts: 97
Thanks: 75
Thanked 0 Times in 0 Posts
Eggweezer is an unknown quantity at this point
Ahh, thanks! I tried the single quotes, but it escaped me that I would have to concatenate the variable (with the periods). Nice! Thank you much!
Eggweezer is offline   Reply With Quote
Old 12-30-2012, 04:40 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,639
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This should also work: header("Location: view_{$galleryName}_images.php");. The problem is that it is greedy when dereferencing the variable, so it doesn't know where your variable name ends. It considered your entire variable to be all valid chars, so it was attempting to resolve $galleryName_images as your variable name.

Always enable your error reporting in development domain (even inline will suffice):
PHP Code:
ini_set('display_errors'1);
error_reporting(E_ALL); 
It should have triggered an error on an undefined variable.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Eggweezer (12-30-2012)
Old 12-30-2012, 06:24 PM   PM User | #5
Eggweezer
New Coder

 
Join Date: May 2012
Posts: 97
Thanks: 75
Thanked 0 Times in 0 Posts
Eggweezer is an unknown quantity at this point
Got it. Thank you Fou-Lu
Eggweezer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Advertisement
Log in to turn off these ads.