user3017315
user3017315

Reputation: 91

Send a variable's value through clicking a link

row['filename'] below contains a filename fetched from database. I want to send the filename to download_file.php when the link is clicked.

<?php 

//other code
$filename=$row['filename'];
echo '<a href="download_file.php?name=$filename">' . "See file name" .'</a>';

?>

but in download_file.php I get only the word $filename instead of its value (the actual filename fetched from the db). How can I pass the value of $filename to download_file.php? Where did I go wrong in my code?

Upvotes: 1

Views: 1480

Answers (3)

GautamD31
GautamD31

Reputation: 28763

Try like

echo '<a href="download_file.php?name="'.$filename.'>See file name</a>';

Or you can directly use " double quotes like :

echo "<a href='download_file.php?name=$filename'>See file name</a>";

Upvotes: 4

tttpapi
tttpapi

Reputation: 887

You used apostrophes as a string mark. If you use quotation marks you can use the anchor like that.

echo "<a href='download_file.php?name=$filename'>See file name</a>";

Upvotes: 2

rray
rray

Reputation: 2556

In single quotes you can't get the value of variables only with double quotes.

change to:

echo "<a href='download_file.php?name=$filename'>See file name</a>";

about quotes in php

Upvotes: 2

Related Questions