3 file upload fields in html form, post to MYSQL DB

Hello All,

I am working on an art submission form for a local museum. I have an html form and i’m using php/mysql. I have all of the fields populating the DB without any problem, but when it comes to the file upload i’m having issues.

The artist is allowed to upload 3 images. Since the images are going to be between 3-5MB I am trying to get the file to upload to a directory and the file name be placed in the DB. I got it to work once, but when I tried to have all three images upload at once it nolonger worked.

Any ideas? Any help would be greatly appreciated!

Below is the code I am currently using. The form has all the fields, but I only have the first art piece selection active in the php code while I test.

[code]

Untitled Document

Artist's Name

Address

City State Zip Code

Day Time Phone Evening Phone

Email Address Artist's Website


Artist Statement/Bio


Artwork 01

Title Date

Medium

Dimensions (h x w x d)

Retail Value Reserve Price

  <p>Dontation (please select one) 
    <select name="a1donation" id="a1donation">
      <option value="Full">Full Donation</option>
      <option value="Split">50/50 Split</option>
    </select>
  </p>
  <p>
    <label for="a1image">Image File</label>
    <input type="file" name="a1image" id="a1image" /><br />
</p>
  <hr />
  <p><strong>Artwork 02</strong></p>
  <p>
    <label for="a2title">Title</label>
    <input name="a2title" type="text" id="a2title" size="45" maxlength="150" />
    <label for="a2date">Date</label>
    <input name="a2date" type="text" id="a2date" size="20" />
  </p>
  <p>
    <label for="a2medium">Medium</label>
    <input name="a2medium" type="text" id="a2medium" size="40" />
  </p>
  <p>
    <label for="a2dimensions">Dimensions (h x w x d)</label>
    <input type="text" name="a2dimensions" id="a2dimensions" />
  </p>
  <p>
    <label for="a2retail">Retail Value</label>
    <input type="text" name="a2retail" id="a2retail" />
    <label for="a2reserve">Reserve Price</label>
    <input type="text" name="a2reserve" id="a2reserve" />
  </p>
  <p>Dontation (please select one) 
    <select name="a2donation" id="a2donation">
      <option value="Full">Full Donation</option>
      <option value="Split">50/50 Split</option>
    </select>
  </p>
  <p>
    <label for="a2image">Image File</label>
    <input type="file" name="a2image" id="a2image" />
  </p>

Artwork 03

Title Date

Medium

Dimensions (h x w x d)

Retail Value Reserve Price

Dontation (please select one) Full Donation 50/50 Split

Image File


[/code]

[php]<?php

$host=“localhost”; // Host name
$username=“"; // Mysql username
$password="
”; // Mysql password
$db_name="****"; // Database name
$tbl_name=“2012Submissions”; // Table name

// Connect to server and select database.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// Get values from form
$name=$_POST[‘name’];
$address=$_POST[‘address’];
$city=$_POST[‘city’];
$state=$_POST[‘state’];
$zip=$_POST[‘zip’];
$day_phone=$_POST[‘day_phone’];
$night_phone=$_POST[‘night_phone’];
$website=$_POST[‘website’];
$email=$_POST[‘email’];
$statement=$_POST[‘statement’];

$a1title=$_POST[‘a1title’];
$a1date=$_POST[‘a1date’];
$a1medium=$_POST[‘a1medium’];
$a1dimensions=$_POST[‘a1dimensions’];
$a1retail=$_POST[‘a1retail’];
$a1reserve=$_POST[‘a1reserve’];
$a1donation=$_POST[‘a1donation’];
//$a1image=$_POST[‘a1image’];

//$a2title=$_POST[‘a2title’];
//$a2date=$_POST[‘a2date’];
//$a2medium=$_POST[‘a2medium’];
//$a2dimensions=$_POST[‘a2dimensions’];
//$a2retail=$_POST[‘a2retail’];
//$a2reserve=$_POST[‘a2reserve’];
//$a2dontation=$_POST[‘a2donation’];
//$a2image=$_POST[‘a2image’];

//$a3title=$_POST[‘a3title’];
//$a3date=$_POST[‘a3date’];
//$a3medium=$_POST[‘a3medium’];
//$a3dimensions=$_POST[‘a3dimensions’];
//$a3retail=$_POST[‘a3retail’];
//$a3reserve=$_POST[‘a3reserve’];
//$a3dontation=$_POST[‘a3donation’];
//$a3image=$_POST[‘a3image’];

// Insert data into mysql
$sql=“INSERT INTO $tbl_name(name, address, city, state, zip, day_phone, night_phone, website, email, statement, a1title, a1date, a1medium, a1dimensions, a1retail, a1reserve, a1donation)
VALUES(’$name’, ‘$address’, ‘$city’, ‘$state’, ‘$zip’, ‘$day_phone’, ‘$night_phone’, ‘$website’, ‘$email’, ‘$statement’, ‘$a1title’, ‘$a1date’, ‘$a1medium’, ‘$a1dimensions’, ‘$a1retail’, ‘$a1reserve’, ‘$a1donation’)”;
$result=mysql_query($sql);

// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;
echo “Back to main page”;
}

else {
echo “ERROR”;
}
?>

<?php // close connection mysql_close(); ?>[/php]

2 ways of doing this. You can make 3 seperate forms with buttons and different names or you have 1 form, named the same (images[]), then use a loop to process the uploads.

Sponsor our Newsletter | Privacy Policy | Terms of Service