By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,645 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,645 IT Pros & Developers. It's quick & easy.

Having trouble passing values via href

P: 2
EDIT: Typo in the title, should read passing values.

Fairly new to php, but I'm trying to pass a value through a link, but it doesn't seem to be working. I don't see any reason why it shouldn't work; perhaps I just misunderstand the concept of passing values. Anyways, here's a quick test page I wrote up using my "strategy" for passing a value.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(!isset($test))
  3. {
  4. $test="no";
  5. }
  6. ?> <html><head><title>test</title></head><body> <a href="http://bytes.com/name.php?show=yes">test</a> <?php
  7. echo $test;
  8. ?> </body></html>
  9.  
What I think the code should do is assign the value of "yes" to the variable "show" when the link is clicked. Then the next section of php code reads the value, which was what I was using to check to see if the value was passed correctly. However, when I click the link, the value of the variable is still displayed as "no." Again, apologies if this is a dumb question. Thanks in advance for your help!
Dec 4 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,355
You haven't explained what the problem is. Just saying something doesn't work doesn't actually tell us anything.

You've posted the code to pass the value 'yes' with a variable name of 'show' using the GET method. You also need to post the code where you try to read the value.
Dec 4 '12 #2

P: 2
Sorry, I'll edit that in there. If I'm understanding you correctly, the part you're referring to where I try to read the value is the
Expand|Select|Wrap|Line Numbers
  1. echo $test;
part. Is this correct?
Dec 4 '12 #3

Rabbit
Expert Mod 10K+
P: 12,355
So you're passing the form to itself and you want to echo the value passed to itself?

You're not doing it correctly.

1) You have no variable named $test.

2) In your link "http://bytes.com/name.php?show=yes", you are actually passing a variable named "show". Hence the word "show" in the link. And you give that variable a value of "yes". Hence the "=yes" part of the link.

3) Because you are passing the data using the GET method, to retrieve the value of "show", you would use this $_GET['show'].
Dec 4 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.