473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Uploading files into a MySQL database using PHP

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.

2 1473
may be single quotation is problem.kindly check it
$sql = "SELECT id,name,mime,size,created FROM file";
Mar 8 '12 #2
Rabbit
12,516 Expert Mod 8TB
On line 12, you have an open parenthesis rather than a close.
Mar 8 '12 #3

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

Similar topics

5
by: hdf | last post by:
hi i have problems uploading my database using phpmyadmin n i want to load it using the ssh termal in setd of phpmyadmin. can anyone hlp
11
by: menmysql | last post by:
i am getting the following error while connecting mysql database using jsp java.sql.SQLException: Communication link failure: Bad handshake can any one tell what is the actual problem
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
9
by: christopher_board | last post by:
Hi all. I am trying to connect to a MySQL Database using PHP on a local machine using locahost. I am using the following code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass =...
1
by: ganeshg | last post by:
Hai All, Please let me know how to insert audio files into mysql database using .net. Thanking you.....
3
by: Suresh P | last post by:
Hi All, I tried to access the mysql database in ODBC using ip address and username/password. It returns, "cannot connect to MySQL server on IP ADDRESS(10060)". This could be related to Firewall...
1
by: nadeenahmed | last post by:
I have Connected to a MySQL Database using a neatbeans editor. Now, I want to use that same database I created earlier on another pc. Can anyone help and tell me how that is done, please? Thank...
6
by: mfaisalwarraich | last post by:
Hi everyone, I am trying to add multiple pinpoint to google map using Lon/Lat. All addresses will be fetched from mysql database using PHP. I have looked at google and searched for it on...
1
by: santhanalakshmi | last post by:
Hi, I wrote some coding, to import excel data in mysql database using PHP Script? But my script, its not all inserting the excel data in mysql database. I don't know, what mistake did i made?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.