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
https://forums.phpfreaks.com/topic/104408-problem-with-variable/
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?

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.

Archived

This topic is now archived and is closed to further replies.

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