View Full Version : Passing variable via hyperlink?

07-25-2012, 04:25 AM
I am trying to understand "Passing variables via hyperlinks".
I found a website that explains how to do that, BUT, it does not work for me.

The site:

The html code

<a href="http://yourdomain.com/catching-var.php?<span class="bold">name=Shaun</span>
<span class="bold">&Lname=Morgan</span>">Test Page 1</a>

The code on the php page receiving and displaying the "name" variables

<hr />

$name = $_GET['name'];
$Lname = $_GET['Lname'];
echo $name.'<br/><br/>';
echo $Lname.'<br/><br/>';

I believe the php code to receive & display the variables appear to be correct, but it seems that the variables are not being passed (or I am doing something wrong).

I would appreciate if someone would please help me understand. Sincerely, Eggweezer
My example is at : http://briskeee.org/

07-25-2012, 04:40 AM
The code on that example will only work if you copy and paste the link into your browser window. If you want the link to work directly do it this way.

<a href="http://yourdomain.com/catching-var.php?name=Shaun&Lname=Morgan">Test Page 1</a>

07-25-2012, 12:18 PM
Thank you very much. That is really cool. I never realized that you could pass a variable that way. That is a useful feature! Thanks again.

07-25-2012, 01:25 PM
$table = "SELECT * FROM users";
$test = mysql_query($table);

echo "<table><tr><th>Username</th>";
echo "<th> </th>";
echo "<th>Created</th>";
echo "<th>Infastructure</th>";
echo "<th>Statename</th>";
echo "<th>Money</th></tr>";
while ($row = mysql_fetch_array($test)) {
echo '<tr><td><a href="profile.php?user='
. $row['username'] . '">'
. $row['username'] . '</a></td><td>
<a href="sendmessage.php?user='
. $row['username'] . '"><img src="images/messageicon.png" alt='
. $row['username'] . '</img></a></td><td>'

. $row['dayregistered'] . '</a></td><td>'
. $row['infrastructure'] . '</td><td> '
. $row['statename'] . '</td><td> $'
. $row['money'] . '</td></tr>';

echo "</table>";
I use this code in my script. Hope it helps.