Hello All, and thank you for taking the time to read this.
I have been running into a mess of problems trying to write a script for uploading files. I had it working perfectly last week, and then suddenly it just stopped and started giving me an undefined index notice, and an empty array.
I've attempted rewriting my php script in various ways, as well as redoing my html form.. i can't fathom what i'm doing wrong. I indeed double checked my php.ini and permissions.. everything is set.
I'm pretty new to server-side scripting so hopefully this doesn't look too bad. I've even created a simpler "TEST" script.
PHP:
In the TEST file:
<?php
// parse the form data and add inventory item to the DB
if (isset($_POST['fileField']));{
$PIC = $_POST['fileField'];
// Place image in the Folder
move_uploaded_file($_FILES['fileField']['tmp_name'],"../images/products/");
var_dump($_FILES);
$_FILES['fileField']['error'];
exit ();
}
?>
and this is what I use in the working file:
<?php
// parse the form data and add inventory item to the DB
if (isset($_POST['SKU'])) {
$SKU = mysql_real_escape_string($_POST['SKU']);
$product_name = mysql_real_escape_string($_POST['product_name']);
$description = mysql_real_escape_string($_POST['description']);
$Category1 = mysql_real_escape_string($_POST['Category1']);
$ProductType1 = mysql_real_escape_string($_POST['ProductType1']);
$License1 = mysql_real_escape_string($_POST['License1']);
$logo = mysql_real_escape_string($_POST['logo']);
$quantity_per = mysql_real_escape_string($_POST['quantity_per']);
$price = mysql_real_escape_string($_POST['price']);
$MSRP = mysql_real_escape_string($_POST['MSRP']);
$discount = mysql_real_escape_string($_POST['discount']);
$discount_enabled = mysql_real_escape_string($_POST['discount_enabled']);
$item_weight = mysql_real_escape_string($_POST['item_weight']);
$item_length = mysql_real_escape_string($_POST['item_length']);
$item_width = mysql_real_escape_string($_POST['item_width']);
$item_depth = mysql_real_escape_string($_POST['item_depth']);
$package_weight = mysql_real_escape_string($_POST['package_weight']);
$package_length = mysql_real_escape_string($_POST['package_length']);
$package_width = mysql_real_escape_string($_POST['package_width']);
$package_depth = mysql_real_escape_string($_POST['package_depth']);
$product_enabled = mysql_real_escape_string($_POST['product_enabled']);
$rank = mysql_real_escape_string($_POST['rank']);
// see if that SKU is an identical match to another product in the system
$sql = mysql_query("SELECT ProductID FROM Products WHERE SKU='$SKU' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output ammount
if ($productMatch > 0){
echo 'Sorry, you tried to place a duplicate "SKU" into the system, <a href="add_product.php">Click Here</a>';
exit();
}
// Add this product into the Database now
$sql = mysql_query("INSERT INTO Products (SKU, ProductShortDesc, ProductLongDesc, CategoryID, ProductTypeID, LicenseID, Logo, QuantityPerUnit, ItemCost, MSRP, Discount, DiscountAvailable, ItemWeight, ItemLength, ItemWidth, ItemDepth, PackageWeight, PackageLength, PackageWidth, PackageDepth, ProductAvailable, Ranking, Date_Added)
VALUES('$SKU','$product_name','$description','$Category1','$ProductType1','$License1','$logo','$quantity_per','$price','$MSRP','$discount','$discount_enabled','$item_weight','$item_length','$item_width','$item_depth','$package_weight','$package_length','$package_width','$package_depth','$product_enabled','$rank',now())") or die (mysql_error());
$pid = $SKU;
// Place image in the Folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'],"../images/products/$newname");
var_dump($_FILES);
$_FILES['fileField']['error'];
exit ();
}
?>
HMTL:
HTML in TEST file:
<body text='#000000'">
<div align="left" id="mainWrapper">
<?php include_once("../templates/template_adminheader.php");?>
<h4>
↓ Add New Inventory Item ↓</h4>
<br />
Fields with an * denote a required field
<form action="add_producttest.php" enctype="mulipart/form-data" name="myForm" id="myForm" method="post">
Picture*
<input type="file" name="fileField" id="fileField" />
Image of Product
<p><label>
<input type="submit" name="button" id="button" value="Add This Item Now" />
</label></p>
</form>
<br/>
</div>
<?php include_once("../templates/template_footer.php");?>
</body>
</html>
In the working file:
<body text='#000000'">
<div align="left" id="mainWrapper">
<?php include_once("../templates/template_adminheader.php");?>
<div id="pageContent"><br />
<div align="center">
<h4>
↓ Add New Inventory Item ↓</h4></div>
<br />
Fields with an * denote a required field
<form action="add_product.php" enctype="mulipart/form-data" name="myForm" id="myForm" method="post">
<table width="90%" border="1" cellspacing="0" cellpadding="6">
<tr>
<td width="11%">SKU*</td>
<td width="70%"><label>
<input name="SKU" type="text" id="SKU" size="75" />
</label></td>
<td width="19%"><p>Enter the SKU of the Item:<br />
<br />
</p></td>
</tr>
<tr>
<td>Product Name*</td>
<td><label>
<input name="product_name" type="text" id="product_name" size="100" />
</label></td>
</tr>
<tr>
<td>Product Description*</td>
<td><label>
<textarea name="description" id="description" cols="64" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td>Category*</td>
<td><label>
<?php dropdown("CategoryID", "CategoryName", "Category", "CategoryName", "Category1");?>
</label></td>
</tr>
<tr>
<td>Product Type*</td>
<td><label>
<?php dropdown("ProductTypeID", "ProductTypeName", "ProductType", "ProducTypeName", "ProductType1");?>
</label></td>
</tr>
<tr>
<td>License*</td>
<td><label>
<?php dropdown("LicenseID", "License", "License", "License", "License1");?>
</label></td>
</tr>
<tr>
<td>Logo</td>
<td><label>
<input name="logo" type="text" id="logo" size="50" />
</label></td>
</tr>
<tr>
<td>Quantity per unit*</td>
<td><label>
<input name="quantity_per" type="text" id="quantity_per" size="4" />
</label> </td>
</tr>
<tr>
<td>Item Cost*</td>
<td><label>
<input name="price" type="text" id="price" size="12" />
</label></td>
<td>Sale Price</td>
</tr>
<tr>
<td>MSRP*</td>
<td><label>
<input name="MSRP" type="text" id="MSRP" size="12" />
</label></td>
</tr>
<tr>
<td>Discount</td>
<td><label>
<input name="discount" type="text" id="discount" size="12" />
</label></td>
</tr>
<tr>
<td>Discount Enabled?</td>
<td><select name="discount_enabled" id="discount_enabled">
<option value="">Select Option</option>
<option value="-1">Enabled</option>
<option value="0">Disabled</option>
</select></td>
</tr>
<tr>
<td>Item Weight*</td>
<td><label>
<input name="item_weight" type="text" id="item_weight" size="12" />
</label></td>
</tr>
<tr>
<td>Item Length*</td>
<td><label>
<input name="item_length" type="text" id="item_length" size="12" />
</label></td>
</tr>
<tr>
<td>Item Width*</td>
<td><label>
<input name="item_width" type="text" id="item_width" size="12" />
</label></td>
</tr>
<tr>
<td>Item Depth*</td>
<td><label>
<input name="item_depth" type="text" id="item_depth" size="12" />
</label></td>
</tr>
<tr>
<td>Package Weight*</td>
<td><label>
<input name="package_weight" type="text" id="package_weight" size="12" />
</label></td>
</tr>
<tr>
<td>Package Length*</td>
<td><label>
<input name="package_length" type="text" id="package_length" size="12" />
</label></td>
</tr>
<tr>
<td>Package Width*</td>
<td><label>
<input name="package_width" type="text" id="package_width" size="12" />
</label></td>
</tr>
<tr>
<td>Package Depth*</td>
<td><label>
<input name="package_depth" type="text" id="package_depth" size="12" />
</label></td>
</tr>
<tr>
<td>Product Available?</td>
<td><select name="product_enabled" id="product_enabled">
<option value="">Select Option</option>
<option value="-1">Enabled</option>
<option value="0">Disabled</option>
</select></td>
</tr>
<tr>
<td>Picture*</td>
<td><label>
<input type="file" name="fileField" id="fileField" />
</label>
</td>
</tr>
<tr>
<td>Ranking</td>
<td><label>
<input name="rank" type="text" id="rank" size="4" />
</label></td>
</tr>
</table>
<p><label>
<input type="submit" name="button" id="button" value="Add This Item Now" />
</label></p>
</form>
<br/>
</div>
<?php include_once("../templates/template_footer.php");?>
</div>
</body>
I'm on GoDaddy servers. I originally was on a Windows IIS with a custom php.ini file, now i'm on a Linux/Apache Server.
😕