Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2012
    Posts
    149
    Thanks
    115
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    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"); 

  • Users who have thanked tempz for this post:

    Eggweezer (12-30-2012)

  • #3
    Regular Coder
    Join Date
    May 2012
    Posts
    149
    Thanks
    115
    Thanked 0 Times in 0 Posts
    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!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    Eggweezer (12-30-2012)

  • #5
    Regular Coder
    Join Date
    May 2012
    Posts
    149
    Thanks
    115
    Thanked 0 Times in 0 Posts
    Got it. Thank you Fou-Lu


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •