Notice: Undefined index: image

This one is driving me nuts, I’m currently making an inventory portal for my business and I’ve created a form that I know works as I use it for other parts of my portal and it passes the data from the form to the php processing page and into the database with no problems. My issue now is this, I’ve created a page I call add_new.html which is the form to add a new item to inventory, this form however has the option to add an image as well. So I have an input box allowing the user to select the image from their pc and it will be uploaded to a folder on the server and the path and rest of the form content stored in MySQL. But, I hit an error of "Notice: Undefined index: image in C:\xampp\htdocs\beta\inventory\add_new_item.php on line 37
ERROR

Here is my add_new.html code:

[code]

.auto-style2 { margin-left: 4px; } .auto-style3 { text-align: left; } .auto-style4 { margin-right: 8px; }
		<legend id="infoLegend">General Information</legend>
		
		<div id="InfoContent"> <table>
				<tbody>
		<tr class="description">
					<td class="part_description" style="height: 65px">Description</td>
					<td class="field" style="height: 65px">
					
					<textarea name="part_description" id="part_description" style="height: 57px"></textarea>
					<input type="hidden" name="" value=""id="">						
					</td>
				</tr>
				<tr class="part_number">
					<td class="part_number">Part Number</td>
					<td class="part_number">
					
					<input type="text" name="part_number" value="" id="part_number">
					</td>
				</tr>
					
				<tr class="model_number">
					<td class="model_number">Model Number</td>
					<td class="model_number">
					
					<input type="text"  name="model_number" value=""   id="model_number"> </td>
				</tr>
				<tr class="serial_number">
					<td class="serial_number">Serial Number</td>
					<td class="serial_number">
					
					
					
						<input type="text" name="serial_number"id="serial_number">
					
					
					
					</td>
				</tr>
				<tr class="item_color">
					<td class="item_color">Color</td>
					<td class="item_color">
					
					
					
						<input type="text" name="item_color" id="item_color">
					
					
					
					</td>
				</tr>
				<tr class="url">
					<td class="label">Manufacture</td>
					<td class="field">
					
					<input type="text" name="manufacture"  id="manufacture">
					</td>
				</tr>
				<tr class="quantity">
					<td class="quantity">Quantity of Item</td>
					<td class="field">						
					<input type="text" name="quantity" id="quantity">
	
											
				<tr class="cost">
					<td class="cost">Purchase Price In Dollars</td>
					<td class="field">
					
					<input type="text" name="cost" id="cost">
					</td>
				</tr>
		<tr class="hardwareConditionName">
					<td class="label">Condition</td>
					<td class="field">
					
					
					
						<select name="condition" id="condition">
						<option value=""></option>
						<option value="New">New</option>
						<option value="Used">Used</option>
						<option value="Refurbished">Refurbished</option>
						</select>
					
					
					
					</td>
				</tr>
				<tr class="hardwareStatusName">
					<td class="label" style="height: 30px">Availability</td>
					<td class="field" style="height: 30px">
					
					
					
						<select name="availability"  id="availability">
						<option value=""></option>							
						<option value="Available">Available</option>
						<option value="Not Available">Not Available</option>
Reason (if not available)
						<select name="reason" id="reason">
						<option value=""></option>
						<option value="Out">Out of Stock</option>
						<option value="Item Broken">Item Broken</option>
						<option value="Manufacture Discontinued">Manufacture Discontinued</option>
						<option value="Other">Other, Read Comments</option>
					</select>
					
					
					</td>
				</tr>
				
					<td>
					
					</td>
				</tr>
				<tr class="comments">
					<td class="comments" style="height: 53px">Comments</td>
					<td class="comments" style="height: 53px">
					
					<textarea name="comments" id="comments" style="height: 50px"></textarea>
					</td>
				</tr>
		</tbody>
		</table>
		</div>
		</fieldset>
</td>
<div id="image" style="height: 190px"></div>
	</tr>
	<tr><td style="height: 174px">
	<fieldset id="image" class="center" style="height: 165px"><legend>Part Image</legend>
	<center style="height: 143px"><p>Select product image to upload<br><br><input type="file" name="image" id="image"></p></center></fieldset>
	<fieldset id="image">
	
	<legend id="infoLegend">Important Dates</legend>
	
	<div id="InfoContent" style="height: 143px"> 
	<table>
	<tbody>
	<tr class="warranty_date">
				<td class="warranty_date" style="width: 115px">Warranty Date</td>
				<td class="warranty_date" style="width: 116px">
				
				<input type="text" name="warranty_date" id="warranty_date" style="width: 112px">&nbsp;
				
				</td>
			</tr>
	
			
			
			
			<tr class="purchase_date">
				<td class="purchase_date" style="height: 30px; width: 115px">Purchase Date</td>
				<td class="purchase_date" style="height: 30px; width: 116px;">
				
				<input type="text" name="purchase_date" id="purchase_date" style="width: 112px">&nbsp;
				
				
				
				</td>
			</tr>
			<tr class="futureuse">
				<td class="futureuse" style="width: 115px; height: 30px;">Future</td>
				<td class="futureuse" style="height: 30px; width: 116px;">
				
				<input type="text" name="futureuse" id="futureuse" style="width: 112px">&nbsp;
				
		
				
				
				</td>
			</tr>
			<tr class="futureuse2">
				<td class="futureuse2" style="height: 23px; width: 115px;">
				
				Future</td>
				<input type="text" name="futureuse2" value="" id="futureuse2" style="width: 112px">&nbsp;
				
				
			</td>

			</tr>
	</tbody>
	</table>
	</div>
	</fieldset></td></tr>
	
	<!----------------- NEW FIELDSET OF FORM ------------------->		
	<tr id = "location">
			 <td id="location" style="height: 57px">
	<legend id="infoLegend">Location</legend>
	
	<div id="InfoContent"> 
	<table>
	<tbody>
	
			<tr class="location">
				<td class="auto-style3" style="height: 30px; width: 92px;">
				
				Shelf Number</td>
				<td>
				
				<input type="text" name="location" value="" id="location">			
				
				
					</td>
			</tr>
	
	</tbody>
	</table>

	</div>
	</fieldset></td></tr>
	</table>
	<!------------------------------ END OF THIS FIELDSET ----------------------------------->
	
   <table id="submitform">
	<tbody>
                <tr><td><br></td></tr>
                <tr>
                    <td colspan="2">
                          <input type="submit" value="Add New Item" id="form_submit">

										<input type="reset" value="Reset Form" class="table_button">
							</td>
                </tr>
            </tbody>
        </table>
	

			</form>

    
</div>
[/code]

And here is my add_new_item.php Code:

[php]

Untitled 2 <?php

$host=“localhost”;
$username=“root”;
$password=“xxxxx”;
$db_name=“portal”;
$tbl_name=“inventory”;

mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// Get values from form
$part_description=$_POST[‘part_description’];
$part_number=$_POST[‘part_number’];
$model_number=$_POST[‘model_number’];
$serial_number=$_POST[‘serial_number’];
$item_color=$_POST[‘item_color’];
$manufacture=$_POST[‘manufacture’];
$quantity=$_POST[‘quantity’];
$cost=$_POST[‘cost’];
$condition=$_POST[‘condition’];
$availability=$_POST[‘availability’];
$reason=$_POST[‘reason’];
$comments=$_POST[‘comments’];
$warranty_date=$_POST[‘warranty_date’];
$purchase_date=$_POST[‘purchase_date’];
$location=$_POST[‘location’];
$image=$_POST[‘image’]; // <---- This is line 37 for my error!

// Insert data into mysql
$sql=“INSERT INTO $tbl_name(part_description, part_number, model_number, serial_number, item_color, manufacture, quantity, cost, condition, availability, reason, comments, warranty_date, purchase_date, location, image) VALUES(’$part_description’, ‘$part_number’, ‘$model_number’, ‘$serial_number’,’$item_color’,’$manufacture’,’$quantity’,’$cost’,’$condition’,’$availability’,’$reason’,’$comments’,’$warranty_date’,’$purchase_date’,’$location’, ‘$image’)”;
$result=mysql_query($sql);

// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;

echo “Back to main page”;
}

else {
echo “ERROR”;
}

// close connection
mysql_close();
?>

[/php]

Just a note that the current code to submit the image and save the image path is NOT what I’m using to submit the form, I want to get passed this image error before I add that.

For input types of file you need:

[php]$image=$_FILES[‘image’];[/php]

You might also want to have a look at this: http://www.w3schools.com/php/php_file_upload.asp

For a site I built I used a piece of script that can do lots of nice things like resize images and make thumbnail copies etc.: [php]http://www.verot.net/php_class_upload.htm[/php], you can see it and try it out here: [php]http://host24.qnop.net/~drdev/index.php[/php] - note that I have added some extra bits to it to show the upload animation etc.

Ok my bad for posting the wrong php code ;D, I have the $image=$_POST(‘image’) in the php form I am using as $image=$_FILES(‘image’) but I still have the same error but I think the issues may be with the name on the input form?
Xerxes I like that site, it looks nice and clean with the layout, too me any way. So my next question for you would be would you be willing to lend me the display code? lol :smiley:

The code for the gallery is another plugin: http://www.jacklmoore.com/colorbox/

Thanks, I’ll take a look, I’m really just looking for code to make my life easier when it comes to my add new items to inventory page. I want to be able to upload the image to a folder and put the path in MySQL along with all the other content on the page as well. I’ve looked at what seems like a billion tutorials and scripts and they either don’t explain very well or the script doesn’t work or it’s either uploading only to a directory or only to MySQL. I’ve actually managed to figure a lot of it out on my own so I now can upload the image to a folder and store the path in MySQL I just need to figure out how to get the rest of the form content to be submitted as well.

Sponsor our Newsletter | Privacy Policy | Terms of Service