PHP Upload Form that includes other fields

Adobe Dreamweaver cs5
November 18, 2010 at 07:02:09
Specs: Windows 7 Ultimate, 2GB RAM
Hi all

I am trying to find a simple PHP upload form that also includes fields for Name, Email Address and Phone number then allows the user to upload a word document or pdf.

I've searched and only found the actual upload form with any other fields but I'm not understanding how to marry the two up?

Any ideas please guys?



I only pretend to know what I'm talking about.

See More: PHP Upload Form that includes other fields

Report •

January 27, 2011 at 07:21:59
Hi Paul,

Are you going to storing the form information in a DB or a file? I just recently did something very similar to this. I wrote the file to a directory on the server and stored the form data along with the file name to a MySQL DB.

This is the php code to write the information to the DB


//This is the directory where images will be saved
$target = "your directory";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form

// Connects to your Database
mysql_connect("yourhost", "username", "password") or die(mysql_error()) ;
mysql_select_db("dbName") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO tableName (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";

Here is the form:

<form method="post" action="addMember.php" enctype="multipart/form-data">

Please Enter the Band Members Name.

Band Member or Affiliates Name:
<input type="text" name="nameMember"/>

Please Enter the Band Members Position. Example:Drums.

Band Position:
<input type="text" name="bandMember"/>

Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.

<input type="hidden" name="size" value="350000">
<input type="file" name="photo">

Please Enter any other information about the band member here.

Other Member Information:
<textarea rows="10" cols="35" name="aboutMember">

Please Enter any other Bands the Member has been in.

Other Bands:
<input type="text" name="otherBands" size=30 />
<input TYPE="submit" name="upload" title="Add data to the Database" value="Add Member"/>

I cannot remember where I found this code but it helped me a lot.

I hope this helps,

Report •

January 27, 2011 at 12:46:22
Thank you very much Rob - I shall use this thank you :o) very kind

I only pretend to know what I'm talking about.

Report •

Related Solutions

Ask Question