$prodId = (int)$_POST['id'];
$grabImage = sprintf("SELECT image_id, image, prod_id
FROM prod_images
WHERE prod_id = %d
ORDER BY image_id", $prodId);
$gotImage = mysql_query($grabImage);
$p = mysql_fetch_array($gotImage);
$k=0;
while($prod_det=mysql_fetch_array($gotImage))
{
$oldimg[$k]=$prod_det['image'];
$imgid[$k]=$prod_det['image_id'];
$k++;
}
if($_FILES['image']['name'] != "")
{
if($oldimg[0] != "")
{
echo $oldimg[0];
@unlink("../images/items/".$oldimg[0]);
$target_path = '../images/items/' .basename($_FILES['image']['name']);
funResizeImagesUserside($_FILES['image']['tmp_name'], $target_path,'height',430,340);
$action = basename($target_path);
#--------------------------------- Update Image
$updateImages = sprintf("UPDATE prod_images
SET image = '%s'
WHERE image_id = %d", $action, $imgid[0]);
$imagesUpdated = mysql_query($updateImages) or die("Images were not updated because: " . mysql_error());
#---------------------------------- Update Color
$updatecolor = sprintf("UPDATE prod_colors
SET color = '%s'
WHERE image_id = %d", $color, $imgid[0]);
mysql_query($updatecolor);
}
else if($oldimg[0] == "")
{
echo "Got here 2";
$target_path = '../images/items/' . basename($_FILES['image']['name']);
funResizeImagesUserside($_FILES['image']['tmp_name'], $target_path,'height',430,340);
$action = basename($target_path);
#--------------------------------- Update Image
$updateImages = sprintf("UPDATE prod_images
SET image = '%s'
WHERE image_id = %d", $action, $imgid[0]);
$imagesUpdated = mysql_query($updateImages) or die("Images were not updated because: " . mysql_error());
#---------------------------------- Update Color
$updatecolor = sprintf("UPDATE prod_colors
SET color = '%s'
WHERE image_id = %d", $color, $imgid[0]);
mysql_query($updatecolor);
}
else
{
echo "Got here 3";
$target_path = '../images/items/' . basename($_FILES['image']['name']);
#----------------------- Insert Image
funResizeImagesUserside($_FILES['image']['tmp_name'], $target_path,'height',430,340);
$action = basename($target_path1);
$updateImage = sprintf("INSERT INTO
prod_images
(image, prod_id)
VALUES('%s',%d)", $action, $p['prod_id']);
$imagesUpdated = mysql_query($updateImages) or die("Images were not updated because: " . mysql_error());
$igid=mysql_insert_id();
#--------------
$insqry=sprintf("INSERT INTO prod_colors
(color, image_id, prod_id)
VALUES('%s',%d,%d)", $color, $igid, $p['prod_id']);
mysql_query($insqry);
}
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.