1. Computing & Technology

Discuss in my forum

Upload a File and write to MySQL

By , About.com Guide

1 of 4

Create a Database
On our site, we have tutorials about adding data to a MySQL database, and tutorials about uploading files, but recently one of our forum users asked:
"I know how to submit data into a mySQL table through a form. Now I want to upload the image file to the remote directory (say, 'images/') but at the same time save the file-name in the table. " This is a very common question because it has a lot of uses. Often you want a user to be able to upload a photo, but you don't want to bog down your database space by saving all the images directly into the database. You instead save the image to your server, but keep a record in the database of what file was saved so you can easily reference the image when needed. First let's create a database:
CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30)) 
This SQL code creates a database called 'employees' that can hold their name, email, phone and the name of their photo.

©2012 About.com. All rights reserved.

A part of The New York Times Company.