I need some assistance. I'm just learning PHP and found an easy to understand example and implement upload for a file using PHP, MySQL, and HTML. I've provided the fields for the DB, example of the HTML, and example of the PHP script. What I'm looking to do is expand the functionality to allow me the ability to upload up to 3 files at one time writing the id, name, email, phone, and file1, file2, file3 details to the MySQL database and upload the 3 files to a directory on the server.
Can someone show me how the current code I've provided could do this. Obviously, I'm probably looking at creating an array of files. Problem is, I don't know what mods need to be made to the HTML and the PHP.
Database:
id (primary key)
name
email
phone
phone
HTML Form:
<form enctype="multipart/form-data" action="add.php" method="POST">
Company ID: <input type="text" name="id"><br>
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
PHP Script:
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$id=$_POST['id'];
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("xxx.xxx.xxx.xx", "username", "password") or die(mysql_error()) ;
mysql_select_db("myemployees") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$id', '$name', '$email', '$phone', '$pic')");
//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.";
}
?>

