Hello.
I'm getting an undefined index error with the following code and I can't for the life of me figure out why. Any insight would be greatly appreciated.
I'm using an html form and a PHP file to upload images to a directory and write the rest of the form details to my DB. The images get uploaded to the directory just fine, but it's not writing the rest of the data to the DB for some reason.
.html form
<html>
<form enctype="multipart/form-data" action="add.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>
<input type="submit" value="Add">
</form>
</html>
and here is the add.php file for uploading and writing to the database
<?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
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("localhost", "un", "pw") or die(mysql_error()) ;
mysql_select_db("database") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `products` VALUES ('$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.";
}
?>
the undefined index error I'm getting is:
"Undefined index: uploadedfile in /Applications/MAMP/htdocs/upload/add.php on line 24"
then below that I get the upload confirmation message that reads;
"The file has been uploaded, and your information has been added to the directory"
thanks a lot in advance!