troubleshooting Question

Grab empty value that has an id from db

Avatar of pingeyeg
pingeyeg asked on
PHP
14 Comments1 Solution281 ViewsLast Modified:
I'm a bit perplexed here.  I am wanting to update the value for an entry in the db, but I can't seem to do it.  The empty value has an id, but when I try to write a conditional to look for that id and empty value, I'm returned the next id, which does have a value.  Is this not possible?  In other words, it looks like this:

id     value        prod_id
65                     756
66    image1      756
67    image2      756
68    image3       756

I want to fill in the blank value of id 65 with a file name, but I can't seem to do it.  Any ideas?
$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);
			}
		}

Open in new window

ASKER CERTIFIED SOLUTION
nitinsawhney

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”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.

-Mike Kapnisakis, Warner Bros