1. Computing

Discuss in my forum

Recently qamarulhuda posted in our forum:

"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 good way to keep track of uploads. You can associate a file with a user in the database, but not bog things down by saving the file directly into the database. We have tutorials about uploading files, and about adding data from forms. We just need to combine these concepts together, and have it do both things. Our new tutorial gives a demonstration of how to do this.

Comments
August 27, 2006 at 2:35 pm
(1) Tiago Schardong says:

Hello Angela,

Im Tiago and Im from Rio de janeiro, Brasil. Im trying to learn about php & MySQL and your tutorials are very helpful tanks for that!

Im having a problem in the “Upload a File and write to MySQL” tutorial. Im checked the path and my password many times and i keep having the message “permision denied”. The complete message is:

________________________________________________

“Warning: move_uploaded_file(img/Photo 116.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/restricted/home/schardongdesign/public_html/add.php on line 21

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/home/restricted/home/schardongdesign/tmp/phpUsn37o’ to ‘img/Photo 116.jpg’ in /home/restricted/home/schardongdesign/public_html/add.php on line 21
Sorry, there was a problem uploading your file.

________________________________________________

If you have an idea about what am I doing rong please tell me!

Tanks!

July 21, 2008 at 6:27 am
(2) Gareth Jones says:

Hi Tiago,

Your file permissions must be wrong they need setting to 777. This is relatively easy to do if you use an FTP client e.g. Cyberduck or Transmission simply right mouse click on the “uploads” folder and change the settings to read/write/modify for all e.g. 777.

Hope this helps.

Thanks

Gareth Jones

February 19, 2009 at 4:47 am
(3) sisira says:

hello freind,

i used the above coding to upload a file to a serer and enter data to a data base. The file uploading happens perfectly. But the data didnt go to the data base. what might be wrong?

Untitled Document

October 22, 2009 at 1:26 pm
(4) SouthWind21 says:

Printing their garbage to buy up the planet and make us their slaves. ,

April 25, 2010 at 11:56 am
(5) Ikkuh says:

For the dutch people I have a simple to follow article. In this artikel you can make your own web application with PHP en MySQL step by step.
Part 1: Connecting to a MySQL server using php
Part 2: Adding data to your MySQL server using PHP

April 29, 2010 at 12:19 pm
(6) Lee Crites says:

My question is this: why not put the images into a table as well? That’s how we do it, and it seems to work out really well. Is the problem not knowing how to display the image later? Or not knowing how to copy it into the MySQL database? Or is there some kind of (perceived) access time issue?

May 13, 2010 at 11:01 am
(7) Eman M. Youssef says:

Hello! Mrs. Angela
I pay lots of precious for your efforts. You are really helpful. I am from Egypt and I have recently learned how to build database ,making entities, and table, but my own problem is that when I write query sometiemes not run correctly , especially in SELECT order. Can you provide me some more about that?

May 25, 2010 at 4:13 pm
(8) chibueze says:

Good day Angela
I am a student from Nigeria and i am writting my project in school and it is titled “DESIGN OF A WEB GUESTBOOK” but i dont really know what this web guest book is all about and how it works. will a database be needed, how is it related to the website? please if any body has any material that will help me out i will appreciate .thanks

May 26, 2010 at 5:15 am
(9) Muzammil says:

i m currently studied php and want to create system in which upload my image file into server folder and save its details in mysql database for this purpose i used your article “Upload a File and write to MySQL”
i have problem in retrieving
it show email and phone perfectly but dont show image name or image and also all data store in mysql db perfectly.

my code for form:

Untitled Document

Name:
E-mail:
Phone:
Photo:

code for processing data:

code for view data:
<?php
// Connects to your Database
mysql_connect("localhost", "sqluser", "786dev") or die(mysql_error()) ; mysql_select_db("almrc") 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 " “;
echo “Name: “.$info['name'] . ” “;
echo “Email: “.$info['email'] . ” “;
echo “Phone: “.$info['phone'] . ” “;
}
?>

Note: i m using localhost as a server.

July 17, 2010 at 8:50 am
(10) Eman Youssef says:

Hello! Ms.Angela,
I am so grateful to such a brillient and helpful woman like you.I learned more about database and SQL from you.My question is that ; do I store some tables /or data or files or images file in SQL , then I follow the same message with some changes to return my demand from the SQL?
Best regards,
eman

July 22, 2010 at 4:38 am
(11) Farhan Niazi says:

@Muzammil

retrieve the image location from the database and also when you echo that location use the img tags of html

eg.

July 28, 2010 at 7:26 am
(12) dave says:

i used this article to learn how to upload data including images. the question i have is there a way to re-size the image on retrieval?

July 13, 2011 at 9:11 am
(13) Amar Saxena says:

Hello Angela Bradley,
i like your notes which is very useful for anyone.
i read and apply “uploading the file” and save the file in my system which is not visible.
told me a solution.

September 6, 2011 at 7:19 am
(14) seun says:

thanks just hope it works

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>
Top Related Searches images

©2013 About.com. All rights reserved.