-1

As per my last question I hv successfully created a database 'test' and a table 'list' and easily updating the info from webpage to database..but now I stuck on 'image' ..I have different images for different id in db..so i hv created an 'image' column

I am simply calling or fetching image from databse via this code

<img src="<?php echo $rows['image']; ?>"  />

Now the problem is that how I update this image with a new one is there is any short or simple method to do so????

Swati Kanojia
  • 11
  • 1
  • 2
  • 7
  • 1
    Do you think we have any idea what you last question was about? – samayo Apr 26 '13 at 17:20
  • Unfortunately you are not showing any code whatsoever about how you are trying to POST this new image value. – Mike Brant Apr 26 '13 at 17:22
  • there's plenty of Q&A on this site about storing files in a db, particularly images, and how to retrieve/display them. Take some time to search for them. because we're not here to repeat ourselves about how DUMB it is to store images in a db. – Marc B Apr 26 '13 at 17:26
  • @All actually my last question was too long so I dont wish to waste all of urs time and this question is again related to that last one. So I thought of asking this to those who helped me out of my last query :) anyways thanks for responding. – Swati Kanojia Apr 26 '13 at 17:36

2 Answers2

0

You need to run an UPDATE query on the row you want to change. You need the primary key (I'll use 'id' as the name) of that row, so that SQL knows which row needs to be updated.

UPDATE `list` SET image = '$newImageSrc' WHERE id = '$idOfExistingRow'
Cory Shaw
  • 1,130
  • 10
  • 16
0

I quess that you inside your database table store the name of the image.

So what you have to do to update it to the new image is the following steps:

  • Remove old image
  • Upload new image
  • Update the row in the database to the name of the new image

How to remove old image using PHP:

unlink('directory/images/'.$image);

You might need to do a selection from the database to get the right image name.

How to upload new image using PHP:

Read this page for more informations on uploading files

Then after uploading the new image, you need to change the row in the database.

How to change the row in the database

$sql = "UPDATE FROM `table` SET `imagename` = '$newimagename' WHERE `imagename` = $oldimagename";
$query = mysql_query($sql) or die(mysql_error());

Thats is the steps you need. Ask if you have problems.

Mark Topper
  • 210
  • 1
  • 9
  • http://www.makeathumbnail.com/thumbnails/image164363.jpg this is what I wish ..when i click on upload then a popup mini window open that give me an option to browse image then this old image get chnged – Swati Kanojia Apr 26 '13 at 17:41