I need to pass a php variable using url to use it in the php code of redirected url. The code which I am using for displaying links of users and passing username of clicked link through url is as follows: (I am just using same page, "view.php" when any of the links is clicked for trial)
while($row=mysqli_fetch_array($res)) { ?> <a href="http://localhost/profileviews/view.php?name=' . $row['username'] . '"><?php echo $row['username']; ?></a> <?php }
$name=$_GET['name']; echo $name;
But what is being displayed in view.php page after clicking a link is not the name of user, but just ' . $row['username'] . ' Is anything wrong with the syntax I've used for passing php varaible $row['username'] ? Please help me out! I am new to php.
Try this:
<?php
while($row=mysqli_fetch_array($res))
{
?>
<a href="http://localhost/profileviews/view.php?name=<?php echo $row["username"]; ?>"><?php echo $row['username']; ?></a>
<?php
}
?>
Try this code:
while($row=mysqli_fetch_array($res))
{
echo'<a href="http://localhost/profileviews/view.php?name='.$row['username'].'">'.$row['username'].'</a>';
}
For simplicity:
while($row=mysqli_fetch_array($res))
{
$username = $row['username'];
echo "<a href='http://localhost/profileviews/view.php?name=$username'>$username</a>";
}
If you don't want variable declaration:
echo '<a href="http://localhost/profileviews/view.php?name='.$row['username'].'">'.$row['username'].'</a>';
尝试这个:
<a href="http://localhost/profileviews/view.php?name= <?php echo $row['username']; ?> . "><?php echo $row['username']; ?></a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.