[Mod Edit: this question has been split off of the article: Uploading Files into MySql Database Using PHP]
I can't download.
I keep getting the following error:
I can't download.
I keep getting the following error:
Error! Query failed:
Query was empty
Query was empty
Code:
<?php
// Connect to the database
$dbLink = mysql_connect("localhost","root","");
if (!$dbLink)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("filestorage", $dbLink);
// Query for a list of all existing files
$sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
$result = mysql_query($query,$dbLink)
or die("Error! Query failed: <pre>". mysql_error($dbLink) ."</pre>");
// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
// Print the top of a table
echo '<table width="100%">
<tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b> </b></td>
</tr>';
// Print each file
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a href='get_file.php?id={$row['id']}'>Download</a></td>
</tr>";
}
// Close table
echo '</table>';
}
// Free the result
//$result->free();
mysql_free_result($result);
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}
// Close the mysql connection
mysql_close($dbLink);
?>
Comment