Reputation: 166
I'm trying to make automatically generated pages for users based on the username. Basically I'm creating a table in HTML which displays all the users currently registered. The names are hyperlinks which redirect to a page in which I will post a welcome message.
The problem is that I don't know how to pass the name of the user I click on to the next page.
<table border='1'>
<tr>
<th>Username</th>
<th>Email</th>
</tr>
<?php
while($currentRow = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td><a href='/templates/profile.php?name='". $currentRow['name'] .">" . $currentRow['name'] . "</a></td>";
echo "<td>" . $currentRow['email'] . "</td>";
echo "</tr>";
}
?>
As you can see, I tried using get, but it won't work, I think it's because it doesn't know what I'm clicking on. The point is that I want the page with the welcome message say something like "welcome, $username". Any ideas?
Upvotes: 0
Views: 109
Reputation: 458
echo "<td><a href='/templates/profile.php?name=". $currentRow['name'] ."'>" . $currentRow['name'] . "</a></td>";
close the single code after name value you are sending in a tag.. thats it.
Upvotes: 0
Reputation: 259
You are closing the string with single quotes "'" that is why $_GET does not work. Replace profile.php?name='" with profile.php?name=" and also remove the single quote on the other end.
Upvotes: 3
Reputation: 14523
You have need remove single quote after ?name= and add it to before character >
Use
echo "<td><a href='/templates/profile.php?name=". $currentRow['name'] ."'>" .
$currentRow['name'] . "</a></td>";
Instead of
echo "<td><a href='/templates/profile.php?name='". $currentRow['name'] .">" .
$currentRow['name'] . "</a></td>";
Upvotes: 0