0

I'm new to PHP and I'm having a problem.

I have two PHP Scripts and I'm trying to pass a variable from home.php file to friend_home.php.

home.php script:

'<a href="friend_home.php?value='.$friend_row['username'].'">'<?php echo $friend_row['username'] ;
?>'</a>'

friend_home.php script:

<?php
    echo $_GET['value'];
a?>

But I'm getting this as output:

'.$friend_row['username'].'

and not the actual value itself.

Any help would be appreciated, thank you :)

Panda
  • 6,955
  • 6
  • 40
  • 55
Raiyu
  • 101
  • 10

2 Answers2

1

Your link isn't formatted properly, try this instead:

<?php echo '<a href="friend_home.php?value='.$friend_row['username'].'">'.$friend_row['username'].'</a>'; ?>

southpaw93
  • 1,891
  • 5
  • 22
  • 39
1

You need to know two things:

  • The php code start with <?php and end with ?>.
  • You can output one variable with echo.

So, if you're out of the <?php tag, and you want output a variable, you need to do something like this:

<a href="friend_home.php?value=<?php echo $friend_row['username']; ?>">
<?php echo $friend_row['username']; ?>
</a>

Even better, since you've a query string parameter, you may want url-encode it, and use htmlspecialchars to the username.

<a href="friend_home.php?value=<?php echo urlencode($friend_row['username']); ?>">
<?php echo htmlspecialchars($friend_row['username']); ?>
</a>
Federkun
  • 36,084
  • 8
  • 78
  • 90