0

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();
    ?>
4
Contributors
6
Replies
30
Views
1 Year
Discussion Span
Last Post by amigura
0

$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']}";
0

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

0

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.

0

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.