SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variables are empty????

    Hi there and thanks for reading. I came across a programming issue that I've never seen before and it happens to me every once and a while. Perhaps I'm missing something obvious, or skipped a chapter way back when. Occasionally when I set a variable from a POST or GET request the variable value can not be accessed. This only happens sometimes - once in a blue moon. It seems as though it's just the variable name that I'm using. I've made sure that it's not a reserved word and I never get any syntax errors while debugging. It's a strange bug and I usually can get around it by just renaming the variable. Still however, I'd like to know why PHP is doing this, or better yet, what I'm doing wrong. I'm sure PHP is doing exactly what it is told. Thanks!

  2. #2
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give an example of your code you're using when this happens.
    - the lid is off the maple syrup again!

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code that is giving you the problem?

    edit: Opps too late
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    empty variables

    It's really not complex code or anything. Here's an example of what I'm talking about.

    PHP Code:
    $stuff $_POST['fieldName'];

    echo 
    $stuff
    The variable stuff will empty. However if I change it to something like:

    PHP Code:
    $stuff2 $_POST['fieldName'];
    echo 
    $stuff2
    Then stuff2 isn't empty. It's a strange error but only happens once and a while. Usually it tends to occur when I'm using sessions. Any ideas?

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    We need to see the exact code (all of it) to determine if there is any reason that your getting this problem, you say that your getting this using sessions, my first questions would be.

    Where are you starting sessions in your script, are any of your session variables the same name as the variable name given to the POST value thats vanishing and do you have Global variables enabled on your server ??
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mandes..thanks for your response. I don't have the code right now because I'm at the office. It's just a question that crossed my mind so I figured I'd post it. I'm staring sessions at the top of my scripts and I wasn't naming these variables the same as my session variables. I thought of that. I understand though that without code it can be difficult to address the issue. Just figured I'd ask. Thought perhaps someone else has ran into the issue before.


Bookmarks

Posting Permissions

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