Jump to content

download by file id


chris11

Recommended Posts

What ive done is upload a fie to my server and categorized it in mysql with an id name.

 

Im trying to fetch that file by calling for the id name "download.php?id=" and print or echo it a link with the file name not id number. This is what im working with and am getting an Parse error: syntax error, unexpected '<' in /home... on line blue

<?php
$query = "SELECT id, name FROM uploads";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))

[color=blue]<a href="download.php?id=<?php echo urlencode($id);?>"><?php echo urlencode($name);?></a> <br>[/color]
}
?>

 

So yeah. Ive been messing around with it and I magically fix one error only to refresh to another .

 

Any insight would be awesome.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/160208-download-by-file-id/
Share on other sites

This should work:

<?php
$query = "SELECT id, name FROM uploads";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0){
echo "Database is empty <br>";
}
else{
while(list($id, $name) = mysql_fetch_array($result)){
	echo '<a href="download.php?id='.$id.'">'.$name.'</a><br />';
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/160208-download-by-file-id/#findComment-845331
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.