1. Home
  2. Computing & Technology
  3. PHP / MySQL

Upload a File and write to MySQL

By Angela Bradley, About.com

4 of 4

Viewing Your Data

<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ;
mysql_select_db("Database_Name") or die(mysql_error()) ;

//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees") or die(mysql_error());

//Puts it into an array
while($info = mysql_fetch_array( $data ))
{

//Outputs the image and other data
Echo "<img src=http://www.yoursite.com/images/".$info['photo'] ."> <br>";
Echo "<b>Name:</b> ".$info['name'] . "<br> ";
Echo "<b>Email:</b> ".$info['email'] . " <br>";
Echo "<b>Phone:</b> ".$info['phone'] . " <hr>";
}
?>

This script very simply queries the database and retrieves all of the information in it. It then echos each back until it has shown all the data.

To show the image, we just use normal HTML for the image, and only change the last part (the actual image name) with the image name stored in our database. For more information on retrieving information from the database, read this tutorial.

4 of 4

Index: Upload a File and write to MySQL

  1. Create a Database
  2. Creating a Form
  3. Processing the Data
  4. Viewing Your Data

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP with MySQL
  5. Upload a file to your server and add it's details to MySQL - SQL Upload File

©2008 About.com, a part of The New York Times Company.

All rights reserved.