Jump to content

Downloading From Database


robyngae

Recommended Posts

I want to be able to show contents of a table and allow someone to download it. I have a code that shows the contents and another that lists the name for download but wish to combine these together and keep getting errors.The second problem is that when I download using script3 it is empty.Script 1 to display contents which works.<?phpinclude "opendb.php";$sql = "Select * From Assessments";$recordSet = mysql_query($sql, $conn);?><h1 align="center">Assessments</h1><table align= "center" width= "90%" border="0"><tr> <td width="30%"> <h3><strong>Name</strong></h3></td> <td width="70%"> <h3>Due Date</h3></td> </tr><?php while ($record = mysql_fetch_array($recordSet)) { echo "<tr> <td> $record[name] </td> <td> $record[Due_Date] </td> </tr>"; } mysql_close($conn);?></table>.........................Script 2 displays the name of the file only and links to download script, as you can see I have tried to incorporate with #1<?phpinclude "opendb.php";$query = "SELECT * FROM Assessments";$result = mysql_query($query);$name = 'name';$Due_Date = 'Due Date';while($record = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<li> {$record['name']['Due Date'] } <a href=download.php?id={$record['id']}> {$record['name']} </a> </li>";}include "closedb.php";?>...........................Script 3 downloads an empty file<?phpif(isset($_GET['id'])) {include 'opendb.php'; //get the file with the id from database $id = $_GET['id'];$query = "SELECT name,type,size FROM Assessments WHERE id = $id"; $result = mysql_query($query) or die('Error, query failed'); list($id, $name, $type, $size, ) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; mysql_close($conn); exit;}?>If anyone could help it would be appreciated, I have been tearing my hair out.Robyn

Link to comment
Share on other sites

You never assign anything to $content. Also, you have a syntax error on this line: list($id, $name, $type, $size, ) = mysql_fetch_array($result);

Link to comment
Share on other sites

You never assign anything to $content. Also, you have a syntax error on this line: list($id, $name, $type, $size, ) = mysql_fetch_array($result);
Thank you Synook I have script 3 and it is now downloading, I still have the problem of trying to add a download link to script 1 or the fields from 1 to script 2Robyn
Link to comment
Share on other sites

Thank you Synook I have script 3 and it is now downloading, I still have the problem of trying to add a download link to script 1 or the fields from 1 to script 2Robyn
I am over the moon, with much trial and error I have them combined so no longer need any help, on this one at least.Robyn
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...