Download Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shakhawat
    New Member
    • Oct 2011
    • 4

    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
    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>&nbsp;</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);
        ?>
    Last edited by Frinavale; Nov 2 '11, 03:14 PM. Reason: Added code tags. Please post code in code tags. Please do not post questions about your application's problems in an article thread. Your question has been moved into it's own thread. Please start a t
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    you initialized $sql but you passed $query query was definitely empty

    Comment

    Working...