Hi all I searched forum but couldn't fine the right answer I was looking for.
I found a script online to help me with uploading a record to my database and the file to directory and name to database. I cannot get it to work and I cannot pin point why. When I add the info I just get the error "Sorry, there was a problem uploading your file. from my add.php"

All help is greatly appreciated!


My database looks like this:
Database - La_Casita_db
table name - Products
fields -product_id
product_name
product_image
product_info
product_status
product_price
product_category
product_type

form - insertrecord.php

<form enctype="multipart/form-data" action="add.php" method="POST">
Name: <input type="text" name="product_name"><br>
Info: 
<textarea name="product_info" rows="5"></textarea>
<br>
Price: <input type="text" name = "product_price"><br>
Category:   <label>
    <select name="product_category">
      <option selected="selected"> </option>
      <option value="product_category">Furnishings</option>
      <option value="product_category">Lighting</option>
            <option value="product_category">Decorative Items</option>
      <option value="product_category">Accessories</option>

    </select>
    </label><br>
Status    <label>
  <select name="product_status">
      <option selected="selected"> </option>
      <option value="product_status">In Stock</option>
      <option value="product_status">Sold Out</option>
  </select>
    </label><br>
Photo: 
<input type="file" name="product_image"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="submit" value="Add">
</form>

add.php

<?php

//This is the directory where images will be saved
$target = "../RAW/images/";
$target = $target . basename( $_FILES['product_image']['product_name']);

//This gets all the other information from the form
$product_name=$_POST['product_name'];
$product_info=$_POST['product_info'];
$product_price=$_POST['product_price'];
$product_category=$_POST['product_category'];
$product_status=$_POST['product_status'];
$product_image=($_FILES['product_image']['product_name']);

// Connects to your Database
mysql_connect("localhost:8888", "root", "root") or die(mysql_error()) ;
mysql_select_db("La_Casita_db") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO `Products` VALUES ('$product_info', '$product_name', '$product_price', '$product_image', '$product_category', '$product_status',)") ;

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

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['product_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.";
}
?>

to access file names in the $_FILES array you need to use 'name' not 'product_name'
ex.

$_FILES['product_image']['name']

Thanks Keith
I now have the script uploading the image to correct destination with this script, but it is not adding the information to my database.
Any suggestions?

<?php

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

//This gets all the other information from the form
$product_name=$_POST['product_name'];
$product_info=$_POST['product_info'];
$product_price=$_POST['product_price'];
$product_category=$_POST['product_category'];
$product_status=$_POST['product_status'];
$product_image=($_FILES['product_image']['name']);

// Connects to your Database
mysql_connect("localhost:8888", "root", "root") or die(mysql_error()) ;
mysql_select_db("La_Casita_db") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO `Products` VALUES ('$product_info', '$product_name', '$product_price', '$product_image', '$product_category', '$product_status')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['product_image']['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.";
}
?>
This question has already been answered. Start a new discussion instead.