Jump to content

problem with variable


tmyonline

Recommended Posts

Guys: I'm having this problem that bugs me.  Here's a snippet of my code:

 

  $contactID = $_GET['id'];

  echo 'contactID = ' . $contactID;

 

  if (isset($_POST['send'])) {

    echo 'contactID = ' . $contactID;  // nothing appeared, wonder why ? !

  }

 

The problem is that, somehow, my "$contactID" variable lost its value inside the if statement.  It didn't help when I used $_SESSION['contactID'] = $_GET['id'] either.  Any ideas ?  Thanks.

 

Link to comment
Share on other sites

What's the actual output from the above? Do you mean that nothing from this line:

echo 'contactID = ' . $contactID;   // nothing appeared, wonder why ? !

is displayed?

 

In which case, the if statement is evaluating to false. You appear to be using get and post. Perhaps that is the problem?

Link to comment
Share on other sites

The actual output is:

 

contactID =

 

So, contactID lost its value.

 

The if statement did evaluate to true because other things (not shown) inside the if statement were processed as expected.

 

As for the potential complication due to using post & get, I just switched everything to "get" but it didn't help.

 

I used $_GET['id'] to get the id value from the url.  I'm not sure how that can conflict with the method specified in my form.

Link to comment
Share on other sites

If you have a session variable by the same name, it is highly likely that register globals are on and the various variables with the same name are overwriting each other. If not, then you really need to post your actual code.

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.