We help IT Professionals succeed at work.
Get Started

Grab empty value that has an id from db

pingeyeg
pingeyeg asked
on
277 Views
Last Modified: 2012-06-21
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

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

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.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE