I have a simple form here:
<form method="post" enctype="multipart/form-data" action="php/uploadFile.php">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
Select File From Your Computer:<br />
<input name="userfile" type="file" id="userfile"><br />
Declare Product Type: <br />
<input name="product" type="text" id="product"><br /><br /><br />
<input name="upload" type="submit" class="box" id="upload" value=" Upload ">
</form>
Here is the uploadfile.php:
<?php
$uploadDir = '../img/products/';
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$protype = $_POST['product']['product'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
}
if (!$result) {
echo "Error uploading file";
exit;
}
// Create connection
$con = mysql_connect("localhost","root","open4you");
mysql_select_db("products");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO productimages (name, size, type, path, product ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$protype')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
mysql_close($con);
echo "<br>Your Files Were Uploaded<br>";
}
?>
When running this code, everything works and writes to the database and file location. However, the products field does not write and I receive an error that states:
Undefined index: product in C:\wamp\www\2CO960\php\uploadFile.php on line 10
Any Ideas?
Any help would be greatly rewarded, with praise!