Having a problem with updating a picture.I need to replace the current picture in the DB by allowing the users to browse a picture and uploading it.And if the user did not upload any image I need to keep the current picture as it is.

I wrote something like this,but its not working ..

if (isset($_POST['btnModifyCategory'])){
	
	$cid         = $_POST['catId'];
	$name2        = $_POST['txtName'];
	$description2 = $_POST['catDesc'];

	if(isset($_FILES['file']))
	{
			$image2 = uploadImage();	
	}
	 	
	//update the database with new values.
	if(isset($_FILES['file']))
		{
			if($_FILES['file']['name'] != "")
			{
				$sql2    = "UPDATE tbl_category SET cat_name ='$name2', cat_description='$description',cat_image='$image' WHERE cat_id = '$cid'";
				$result2 = mysql_query($sql2) or die(mysql_error());
			}
			else
			{
				$sql2    = "UPDATE tbl_category SET cat_name ='$name2',cat_description='$description' WHERE cat_id = '$cid'";
				$result2 = mysql_query($sql2) or die(mysql_error());
			
			}
	}
}

(Im not posting the uploadImage() here ,since it is working properly.)
How can I do it..Can someone do it for me.Thank you..!

Isnt there anyone who can help me with this issue?? any expert?? Please..:(

Define not working. Have you done any debugging and isolated where it is having a problem? You presumably have a test environment where you can try this. We don't. When I started working on computers we had to desk check everything because there was no choice. Now we can let the computer do some of the work for us. When something doesn't work, you debug it and try to determine what isn't working the way you expected. There are some better ways but the simple echo command can be used to give you more info on the value of variables at different points in the program so you can see if it doing exactly what you expected it would. If the database reads or writes aren't working properly you can echo the select / insert / update command and then try it in phpMyAdmin to see what it returns.

Firstly I don't understand why in one place you set $description2 but everywhere use $description? The same with $image. Check the names, are they really correct?

Don't know what your function uploadImage() returns, but in the database you need to store only the picture name. Take a look at this article if you have problems with uploading.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.