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.

    <?php
    // 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

    $progressid=$row['Progressid'];
    //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%">
                    <tr>
                        <td><b>Name</b></td>
                    </tr>';

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

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

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

    // Close the mysql connection
    $dbLink->close();
    ?>

$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'];
Member Avatar
diafol

@Sophia - get an editor or IDE that checks code and automatically flags errors.

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.

Member Avatar
diafol

Syntax error on line 1? Doesn't sound as though it's anything to do with the SQL statement.

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