with the sql queries in the download.php script. you arent quite done getting variables.
mysql_query() returns a resource, not actually what you tried to query for, so the line
$filename = mysql_query("SELECT filename FROM scripts WHERE id='$id'") or die(mysql_error());
isnt going to get you exactly what you want. $filename will contain the resource id of the sql link. not the filename.
you will need to do
$result = mysql_query("SELECT filename FROM scripts WHERE id='$id'") or die(mysql_error());
$filename1 = mysql_fetch_row($result);
$filename = $filename1[0];
also, you will want to modify your header() call to be something like this:
<?
//...
header("Content-type: application/octet-stream"); //prompt for download
header("Content-disposition: attachment; filename=$filename"); //specify the filename to show
readfile("scripts/$filename"); //output the data of the file
exit;
?>