Uploading multiple files to server writing detail to MySQL

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 8
Joined: Sat Jan 29, 2011 10:22 am
Location: Byron, Wyoming

Sat Jan 29, 2011 11:46 am

Ok, I changed some of your code to match a project I have been working on myself. If you look at the code, you'll see it will work for your project as well. Here's what I came up with that works for me.

html form
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
<meta name="created" content="Sat, 29 Jan 2011 18:37:45 GMT">
<meta name="description" content="">
<meta name="keywords" content="">

<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/tru ... "></script>
<form enctype="multipart/form-data" action="photo_store.php" method="POST">
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>
Photo: <input type="file" name="photo1"><br>
Photo: <input type="file" name="photo2"><br>
<input type="submit" value="Add">


photo_store.php file


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

//This gets all the other information from the form

// Connects to your Database

$con = mysql_connect("localhost","root","");
if (!$con)
die('Could not connect: ' . mysql_error());

mysql_select_db("my_db") or die(mysql_error()) ;

if ($con) echo "Connection Made!!<br>";

//Writes the information to the database

$sql="INSERT INTO persons (name, email, phone, photo, photo1, photo2)

if (!mysql_query($sql,$con))
die('Error: ' . mysql_error());

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target));
(move_uploaded_file($_FILES['photo1']['tmp_name'], $target1));
(move_uploaded_file($_FILES['photo2']['tmp_name'], $target2))

//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";


I hope this helps.

Post Reply