Jump to content

trying to overwrite an image


divinedesigns1

Recommended Posts

im trying to over write an item using this code

if($_FILES['images']['tmp_name'] != ""){      $newimg = "$id.jpg";      move_uploaded_file($_FILES['images']['tmp_name'], "inventory_images/$newimg");}

what it does is check to see if the image isnt empty and if it isnt you upload the new image to replace the old one, but so far im having problems with replacing the current image

Link to comment
Share on other sites

What exactly is the problem? What happens when you run that?

im not getting any error it just wouldnt replace the old image with the new one

Link to comment
Share on other sites

now i found the problem -_- bastard

( ! ) Notice: Undefined index: images in C:wampwwwe-commeradmininventory_edit.php on line 95

and this is my script, not sure why its not recognizing the input type

if(isset($_GET['pid'])){					$pid = $_GET['pid'];					$dwl = mysqli_query($con, "SELECT * FROM items WHERE id='$pid' LIMIT 1") or die('Error: ' . mysqli_error($con));					// try to get the info to display					if($dwl){						while($row = mysqli_fetch_array($dwl)){							$id = $row['id'];							$pname = $row['product_name'];							$price = $row['price'];							$details = $row['details'];							$cate = $row['category'];							$subcate = $row['subcategory'];						}						echo '<form action="" method="post">						<table align="center" width="90%">						<tr>							<td>Product Name</td>							<td><input type="text" name="product_name" size="24" value="' .$pname . '"></td>						</tr>						<tr>							<td>Product Price</td>							<td>$<input type="text" name="price" size="2" value="' .$price . '"></td>						</tr>						<tr>							<td>Category</td>							<td><input type="text" name="category" size="24" value="' .$cate . '"></td>						</tr>						<tr>							<td>Subcategory</td>							<td><input type="text" name="subcategory" size="24" value="' .$subcate . '"></td>						</tr>						<tr>							<td>Product Details</td>							<td><textarea name="details" rows="8" cols="30">' . $details . '</textarea></td>						</tr>						<tr>							<td>Product Image</td>							<td><input name="images" type="file"></td>						</tr>						<tr>							<td></td>							<td>								<input type="submit" name="submit" value="Save">							</td>						</tr>					</table>						</form>';						// input the updates						if(isset($_POST['submit'])){							// santize							$pname = mysqli_real_escape_string($con, $_POST['product_name']);							$price = mysqli_real_escape_string($con, $_POST['price']);							$cate = mysqli_real_escape_string($con, $_POST['category']);							$subcate = mysqli_real_escape_string($con, $_POST['subcategory']);							$details = mysqli_real_escape_string($con, $_POST['details']);							// input the update							$upsql = mysqli_query($con, "UPDATE items SET product_name='$pname', price='$price', details='$details', category='$cate', subcategory='$subcate' WHERE id='$pid'") or die('Error: ' . mysqli_error($con));							// try to overwrite the image							$file = $_FILES['images']['tmp_name'];							if($file){								$newimg = $id . ".jpg";								move_uploaded_file($file, "/inventory_images/" . $newimg);								}							//header("location:inventory_list.php");						}					}				}
Link to comment
Share on other sites

try adding enctype="multipart/form-data" to form element, and try adjusting "/inventory_images/" to "inventory_images/" to see if that makes difference.

thanks dsone and justsum

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...