Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If a variable hasn't been defined, I want to define it (easy question) 1

Status
Not open for further replies.

krigbert

Programmer
Jun 2, 2005
95
NO
Poor assed headline, but it is descriptive :p

Here's what I have:

Code:
define("GOTOO", $_GET['goto']);

if (defined('GOTOO')) {

  }else{
  
  define("GOTOO", 2);
  
}

$goto = GOTOO;

So, if goto is defined (in a link), it gets passed over to the constant GOTOO, which I then see if is defined - if it isn't I set it to be the number 2. After all that I set the variable $goto to the value of the constant GOTOO.

Not all that straightforward, but it works in my mind... but not on the computer :p

illustration and webdesign
 
but it works in my mind... but not on the computer :p

is not very specifc, Do you get any error messages? do the values not get assigned exactly what is not working?




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Actually, your call to DEFINE is going to generate a warning when $_GET['goto'] is not set.

I would Check wether $_GET['goto'] is set before using it to define a constant.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
So basically,
Code:
if ( isset( $_GET['goto'] ) 
   $goto = $_GET['goto'] ; 
else 
   $goto = 2 ;
 
tried cut and pasting and tried

Code:
if ( isset($_GET['goto']) ){

   $goto = $_GET['goto'] ;
   
}else{

   $goto = 2 ;
   
}

But it just doesn't seem to pass it along. "$goto = $_GET['goto'];" alone does pass it along, so I'm guessing it's just a typo :l

illustration and webdesign
 
huh?

If $_GET['goto'] is set then $goto will get the value.

If $_GET['goto'] is not set then $goto will get a value of 2.

What doesn't pass?



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Agh, sorry, nevermind, it was the script that was receiving the value that didn't want to take numbers. That does actually work. Barrels o' thanks.

illustration and webdesign
 
o.k, glad you sorted it out.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top