Forum Moderators: coopster

Message Too Old, No Replies

Appended variable to a URL

         

fib_81

5:09 pm on May 9, 2005 (gmt 0)

10+ Year Member



Hi Everyone,

I am actually having troubles in appending a value to a url. For example, I appended a value like this:

echo "<td ><font color=black><a href=test_date.php?=eventid=$link_date><font color=black> $day </a></td></font>";

The problem is that I cannot echo out $eventid to the the new webpage which is test_date.php. I guest my question is can you treat an appended variable to an url as a regular variable and can you actually echo out the appended variable?

Thanks,
Fib_81

jatar_k

5:22 pm on May 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



values appended to urls are passed via the $_GET [php.net] super global array.

The method used on your next page to echo or use that var would be

echo $_GET['eventid'];

you also have a problem with your syntax in that link
test_date.php?=eventid=$link_date

should be
test_date.php?eventid=$link_date

there was an extra = in there

fib_81

7:23 pm on May 11, 2005 (gmt 0)

10+ Year Member



Hi,

Thanks for replying. I fixed the problem and it worked. But now I have another problem. I set a session variable to the appended variable. For example:

$_SESSION['x'] =$_GET['eventid'];

I tried to echo out $_SESSION['x'] at another webpage but it did not work. I don't know why that is happening. Is it possible to set a session variable to an appended variable and read that session variable to other pages?

Thanks,
Fib_81

jatar_k

8:48 pm on May 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yes it is

my wild guess

are you using session_start again on every page? If not, you won't be able to echo the session var

fib_81

9:01 pm on May 11, 2005 (gmt 0)

10+ Year Member



Hi Jatar_K,

I used session_start() for every webpage when setting and echoing a session variable. Would it be reasonable to post part of my code?

Regards,
Fib_81

jatar_k

9:55 pm on May 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



another useful tool is to use

echo '<pre>';
print_r($_SESSION);
echo '</pre>';

to look at the session. I foften use this before and after I set/change session vars to check everything is working properly.

>> post code

sure, The offending snippet of code is just fine.

fib_81

4:05 pm on May 13, 2005 (gmt 0)

10+ Year Member



Hi Jatar_K,

I thought I solved but apparently I did not.

I set my session variable like this:

$_SESSION['test_var']= $_GET['eventid'];
header("Location:./test.php");

Then when I tried to echo the $_SESSION['test_var'] in test.php, I get nothing. I used print_r($_SESSION) to see which session variables are set and I did not see $_SESSION['test_var']. It looks as if $_SESSION['test_var'] was never created or set. Am I am doing something wrong?

I am thinking about just appending a value to the header function that directs user to test.php.

jatar_k

5:18 pm on May 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



then I would track back farther and make sure eventid is set and accessible in the script where you are trying to assign it