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:

$fname=$row['fname'];
echo "<td>";
echo "<a href 'stats.php'>$fname</a>"; 
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!

Recommended Answers

All 5 Replies

Take a look at this line:

echo "<a href 'stats.php'>$fname</a>";

You are missing the = on href.

Member Avatar for Rkeast

Take a look at this line:

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:

echo "<a href='stats.php'>{$fname}</a>";

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; - 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...

echo "<a href='stats.php?param={$row['fname']}'>{$row['fname']}</a>";

To retrieve the variable param from the url simply use $_GET to get its value.

Awesome. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.