Uploading files into a MySQL database using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaigundaraja
    New Member
    • Mar 2012
    • 3

    Uploading files into a MySQL database using PHP

    Code:
    <?php
    //Database Information
    
    $dbhost = "localhost";
    $dbname = "test";
    $dbuser = "username";
    $dbpass = "";
    
    //Connect to database
    
    $dbLink = new mysqli ( $dbhost, $dbuser, $dbpass,$dbname)or die("Could not connect: ".mysql_error(
     
    // Query for a list of all existing files
    $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
    $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>
                        <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();
    }
    else
    {
        echo 'Error! SQL query failed:';
        echo "<pre>{$dbLink->error}</pre>";
    }
     
    // Close the mysql connection
    $dbLink->close();
    ?>
    *************** ***end code*********** *************

    ***********erro r *************** *************** ***

    ( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\lis t_files.php on line 14
  • shanmugamit
    New Member
    • Feb 2008
    • 45

    #2
    may be single quotation is problem.kindly check it
    $sql = "SELECT id,name,mime,si ze,created FROM file";

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      On line 12, you have an open parenthesis rather than a close.

      Comment

      Working...