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

$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']}";
Member Avatar for amigura

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 for 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 for diafol

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

Member Avatar for amigura

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.