By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

Uploading files into a MySQL database using PHP

P: 3
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. //Database Information
  4.  
  5. $dbhost = "localhost";
  6. $dbname = "test";
  7. $dbuser = "username";
  8. $dbpass = "";
  9.  
  10. //Connect to database
  11.  
  12. $dbLink = new mysqli ( $dbhost, $dbuser, $dbpass,$dbname)or die("Could not connect: ".mysql_error(
  13.  
  14. // Query for a list of all existing files
  15. $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
  16. $result = $dbLink->query($sql);
  17.  
  18. // Check if it was successfull
  19. if($result) {
  20.     // Make sure there are some files in there
  21.     if($result->num_rows == 0) {
  22.         echo '<p>There are no files in the database</p>';
  23.     }
  24.     else {
  25.         // Print the top of a table
  26.         echo '<table width="100%">
  27.                 <tr>
  28.                     <td><b>Name</b></td>
  29.                     <td><b>Mime</b></td>
  30.                     <td><b>Size (bytes)</b></td>
  31.                     <td><b>Created</b></td>
  32.                     <td><b>&nbsp;</b></td>
  33.                 </tr>';
  34.  
  35.         // Print each file
  36.         while($row = $result->fetch_assoc()) {
  37.             echo "
  38.                 <tr>
  39.                     <td>{$row['name']}</td>
  40.                     <td>{$row['mime']}</td>
  41.                     <td>{$row['size']}</td>
  42.                     <td>{$row['created']}</td>
  43.                     <td><a href='get_file.php?id={$row['id']}'>Download</a></td>
  44.                 </tr>";
  45.         }
  46.  
  47.         // Close table
  48.         echo '</table>';
  49.     }
  50.  
  51.     // Free the result
  52.     $result->free();
  53. }
  54. else
  55. {
  56.     echo 'Error! SQL query failed:';
  57.     echo "<pre>{$dbLink->error}</pre>";
  58. }
  59.  
  60. // Close the mysql connection
  61. $dbLink->close();
  62. ?>
  63.  
  64.  
  65.  
******************end code************************

***********error *********************************

( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\list_files.php on line 14
Mar 8 '12 #1

✓ answered by Rabbit

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

Share this Question
Share on Google+
2 Replies


P: 45
may be single quotation is problem.kindly check it
$sql = "SELECT id,name,mime,size,created FROM file";
Mar 8 '12 #2

Rabbit
Expert Mod 10K+
P: 12,359
On line 12, you have an open parenthesis rather than a close.
Mar 8 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.