PHP question

se4b4ss

Gawd
Joined
Dec 29, 2000
Messages
513
i am trying to create a series of links on one page that pass a variable to the next page. i always get the last value of the variable from the first page passed to the second page. for instance, if these links were created on the first page...

$value=10;
<a href="/second_page.html?passed_variable=$value">link1</a>

$value=20;
<a href="/second_page.html?passed_variable=$value">link2</a>

...and debug on the second page like...

echo $passed_variable;

...i get the result 20 regardless of which link i click. how do i overcome this?

thanks in advance,
se4b4ss
 
when you click each link, does the url reflect what it should be (ie, is the address "http://www.whatever.com/second_page.html?passed_variable=[10|20]" 10 or 20 respectively).

also, do you have html pages set to be treated as php or something

also, is register_globals on?

also, please use code tags around code (but not the php tags, the color scheme makes them hard to read)
 
All I can think of is buffering of some sort is turned on, so when that line is processed ( by the buffer algo ) it spits grabs the current value of the var, not necessarily the value you passed it.

Not sure tho. That snippet of code should work, as is. Do you have any template systems in place, or buffering of some kind turned on?
 
tim,

yes, the url is correct. yes, html is treated as php. yes, register globals is on. ok.

xor,

i noticed if i remove "<?php session_start();?>" on the second page, the debug outputs the correct value, but, of course, you can't access the rest of the page because i use sessions for my users...:)

thanks,
se4b4ss
 
ok, to simplify the problem, i did this:

<a href="/second_page.html?passed_variable=10">link1</a>
<a href="/second_page.html?passed_variable=20">link2</a>

second page:

echo $passed_variable;

...and got the same results...the url is correct:

../second_page.html?passed_variable=10

yet the screen output is 20.

hmmmm,
se4b4ss
 
think i got it. i used session['passed_variable'] elsewhere. when i changed passed_variable to passed, everything seems to work fine.

thanks for listening to me troubleshoot,:D
se4b4ss
 
ahh the wonders(read: horrors) of register globals being on.
 
Originally posted by se4b4ss
i'm working on it. ;)
Working on it?! How hard could it possibly be? Just add _POST[] or _GET[] to your variable names. Simple. More verbose, even.
 
Originally posted by se4b4ss
think i got it. i used session['passed_variable'] elsewhere. when i changed passed_variable to passed, everything seems to work fine.

thanks for listening to me troubleshoot,:D
se4b4ss
it's definately a good idea to use a descriptive variable name
 
Back
Top