473,378 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Download Problem

[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:
Error! Query failed:
Query was empty
Expand|Select|Wrap|Line Numbers
  1.     <?php
  2.     // Connect to the database
  3.     $dbLink = mysql_connect("localhost","root","");
  4. if (!$dbLink)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }
  8.  
  9. mysql_select_db("filestorage", $dbLink);
  10.  
  11.     // Query for a list of all existing files
  12.     $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
  13.      $result = mysql_query($query,$dbLink)
  14.             or die("Error! Query failed: <pre>". mysql_error($dbLink) ."</pre>");
  15.  
  16.  
  17.     // Check if it was successfull
  18.     if($result) {
  19.         // Make sure there are some files in there
  20.         if($result->num_rows == 0) {
  21.             echo '<p>There are no files in the database</p>';
  22.         }
  23.         else {
  24.             // Print the top of a table
  25.             echo '<table width="100%">
  26.                     <tr>
  27.                         <td><b>Name</b></td>
  28.                         <td><b>Mime</b></td>
  29.                         <td><b>Size (bytes)</b></td>
  30.                         <td><b>Created</b></td>
  31.                         <td><b>&nbsp;</b></td>
  32.                     </tr>';
  33.  
  34.             // Print each file
  35.             while($row = $result->fetch_assoc()) {
  36.                 echo "
  37.                     <tr>
  38.                         <td>{$row['name']}</td>
  39.                         <td>{$row['mime']}</td>
  40.                         <td>{$row['size']}</td>
  41.                         <td>{$row['created']}</td>
  42.                         <td><a href='get_file.php?id={$row['id']}'>Download</a></td>
  43.                     </tr>";
  44.             }
  45.  
  46.             // Close table
  47.             echo '</table>';
  48.         }
  49.  
  50.         // Free the result
  51.         //$result->free();
  52.            mysql_free_result($result);
  53.     }
  54.     else
  55.     {
  56.         echo 'Error! SQL query failed:';
  57.         echo "<pre>{$dbLink->error}</pre>";
  58.     }
  59.  
  60.     // Close the mysql connection
  61.     mysql_close($dbLink);
  62.     ?>
  63.  
  64.  
Nov 2 '11 #1
1 1278
johny10151981
1,059 1GB
you initialized $sql but you passed $query query was definitely empty
Nov 3 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Owen Jenkins | last post by:
I've been using Dev's fantastic InetTransferLib to upload and download files via ftp. Now I'm using the http procedures to have my application download zip files from my website. Although the...
1
by: Owen Jenkins | last post by:
Reposting this message from last week since I have not had a reply so far. Hopefully someone will have an idea? --- I've been using Dev's fantastic InetTransferLib to upload and download files...
14
by: James Wong | last post by:
Hi! everybody, I'm facing a quite strange download problem. I use the following code to download an XML file to client side: With Response ' clear buffer Call .Clear() ' specify the...
1
by: Al Cadalzo | last post by:
I have a web page that allows a user to download data by clicking on a link button. I then use Aspose.Excel (v1.0.3705) to generate the file for download and then I call the "Save" method on the...
1
by: GRE | last post by:
I'm hoping someone can help with this problem; I've seen only a handful of postings related to it, but with no clear resolution. I have an ASP.NET 1.1 page that downloads requested files via the...
5
by: Tim_Mac | last post by:
hi, i read that by adding the following code to by aspx pages, it would not store temporary internet files: Response.Cache.SetCacheability(HttpCacheability.NoCache); it didn't actually work...
1
by: theburnetts | last post by:
I am building an ASP.NET application that has a requirement that the user should be able to download all of the data that they have input into the system and save it to a file on their local PC. ...
2
by: Tim | last post by:
I have developed a web based file manager application. It has a simple interface that allows users to upload and download files. Everything works great except for one new download problem. I am...
0
by: =?Utf-8?B?RG92dmll?= | last post by:
I am running Microsoft XP Professional and Internet Explorer7 (connected through Broadband) I have tried a few times to download a program from the Microsoft website (dotnetfx3setup.exe). After...
4
by: maheswaran | last post by:
HI All, I have problem in files downloading over ssl. When am trying with IE Browser i got "Internet Explorer cannot download 40 from blah.gov Internet Explorer was not able to open this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.