Hi, am trying to display the filename after upload but can't display, instead error message "There are no files in the database" is displayed. Please advise. Thanks.

    // Connect to the database
    $dbLink = new mysqli('localhost','user','','pq');
    if(mysqli_connect_errno()) {
        die("MySQL connection failed: ". mysqli_connect_error());
    // Get the ID
    // Query for a list of all existing files

    //echo $progressid;
    $id= $row['id'];
    echo $id;
    $sql = 'SELECT `id`, `name`, `mime`, `size`, `created`,`Progressid` FROM `tfile` where `id`=$row['id']';    
    $result = $dbLink->query($sql);

     // 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%">

            // Print each file
            while($row = $result->fetch_assoc()) {
                echo "
                        <td><a href='get_file.php?id={$row['id']}'>{$row['name']}</td>

            // Close table
            echo '</table>';

        // Free the result
        echo 'Error! SQL query failed:';
        echo "<pre>{$dbLink->error}</pre>";

    // Close the mysql connection
1 Year
Discussion Span
Last Post by amigura

$sql = 'SELECT id, name, mime, size, created,Progressid FROM tfile where id=$row['id']';

That should give an error. Try this:

$sql = "SELECT `id`, `name`, `mime`, `size`, `created`, `Progressid` FROM `tfile` where `id` = {$row['id']}";

you have included the variable within single quotes on line 14 $row['id']

$sql = 'SELECT id, name, mime, size, created, Progressid FROM tfile where id = '.$row['id'];

Edited by amigura


Hi, tried both of your suggestions but still can't display the filename. The message display "Erreur de syntaxe pr�s de '' � la ligne 1". Please advise. Thanks.


is there any more code before the one above as line 1 is <?php and that looks fine.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.