1

I'm trying to echo a string inside a link, however it doesn't appear on the page. Here's my code:

<?php

$con = mysqli_connect("localhost","user","pass","db");

$term = mysqli_real_escape_string($con, $_GET['search']);

$sql = "SELECT * FROM `users` WHERE username LIKE '%".$term."%'"; 
$r_query = mysqli_query($con, $sql); 

while ($row = mysqli_fetch_array($r_query)){ 
echo '<a href="user.php?username=' . $row['username'] . '>$row['username']</a>';
}

?>

The code previously worked when it just echoed echo $row['username'];

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

1

You are not closing properly the echo string. This works:

echo "<a href=\"user.php?username={$row['username']}\">{$row['username']}</a>";
Peter VARGA
  • 4,780
  • 3
  • 39
  • 75