$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);
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE