943,737 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2240
  • PHP RSS
Sep 25th, 2009
0

Adding links inside php

Expand Post »
Hello, I'm having a strange problem. I'm trying to make a link to a page called stats.php for a series of first names that I have stored in a database. However, when I use the code below the hyperlink ends up being a link to the current page I'm on instead of to stats.php. Any help would be greatly appreciated.

..the following is in a while loop:
php Syntax (Toggle Plain Text)
  1.  
  2. $fname=$row['fname'];
  3. echo "<td>";
  4. echo "<a href 'stats.php'>$fname</a>";
  5. echo "<td>";

Step 2 is that I want the page stats.php to display other stored info about the person, so I need to pass the person's name to to the next page when the link is clicked, and then be able to access the db with it, so if you have any helpful hints on how to do that, I'd appreciate that as well. Thanks!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kadjii is offline Offline
12 posts
since Sep 2009
Sep 25th, 2009
0

Re: Adding links inside php

Take a look at this line:
PHP Syntax (Toggle Plain Text)
  1. echo "<a href 'stats.php'>$fname</a>";

You are missing the = on href.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Sep 25th, 2009
0

Re: Adding links inside php

Click to Expand / Collapse  Quote originally posted by xan ...
Take a look at this line:
PHP Syntax (Toggle Plain Text)
  1. echo "<a href 'stats.php'>$fname</a>";

You are missing the = on href.
Also you might want to enclose your variable with curly brackets to avoid a possible parsing error like this:
PHP Syntax (Toggle Plain Text)
  1. echo "<a href='stats.php'>{$fname}</a>";
Reputation Points: 10
Solved Threads: 2
Light Poster
Rkeast is offline Offline
33 posts
since Aug 2009
Sep 25th, 2009
0

Re: Adding links inside php

Ah! Of course its something so basic that I forgot. Ah well, so goes it when you're a newbie programmer. Thanks a lot. Also, the suggestion for putting curly brackets around the variable will let me omit the first line where I had to convert the variable: $fname=$row['fname']; - and might actually solve a bigger chronic problem I've been having... so thanks for that too.

One last thing, I'm using the following line to send fname when the user clicks on it (using info I found on this site), but I can't figure out how to use it on the next page. I've been scanning the web for info so if I find the answer I'll report back...

PHP Syntax (Toggle Plain Text)
  1. echo "<a href='stats.php?param={$row['fname']}'>{$row['fname']}</a>";
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kadjii is offline Offline
12 posts
since Sep 2009
Sep 25th, 2009
0

Re: Adding links inside php

To retrieve the variable param from the url simply use $_GET['param'] to get its value.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Sep 25th, 2009
0

Re: Adding links inside php

Awesome. Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kadjii is offline Offline
12 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Upload a Thumbnail of selected file
Next Thread in PHP Forum Timeline: Saving a date in MySQL with PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC