943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 38
  • PHP RSS
Aug 31st, 2010
0

How to update a picture

Expand Post »
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 ..

PHP Syntax (Toggle Plain Text)
  1. if (isset($_POST['btnModifyCategory'])){
  2.  
  3. $cid = $_POST['catId'];
  4. $name2 = $_POST['txtName'];
  5. $description2 = $_POST['catDesc'];
  6.  
  7. if(isset($_FILES['file']))
  8. {
  9. $image2 = uploadImage();
  10. }
  11.  
  12. //update the database with new values.
  13. if(isset($_FILES['file']))
  14. {
  15. if($_FILES['file']['name'] != "")
  16. {
  17. $sql2 = "UPDATE tbl_category SET cat_name ='$name2', cat_description='$description',cat_image='$image' WHERE cat_id = '$cid'";
  18. $result2 = mysql_query($sql2) or die(mysql_error());
  19. }
  20. else
  21. {
  22. $sql2 = "UPDATE tbl_category SET cat_name ='$name2',cat_description='$description' WHERE cat_id = '$cid'";
  23. $result2 = mysql_query($sql2) or die(mysql_error());
  24.  
  25. }
  26. }
  27. }
(Im not posting the uploadImage() here ,since it is working properly.)
How can I do it..Can someone do it for me.Thank you..!
Last edited by sami.asanga; Aug 31st, 2010 at 12:14 am.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
sami.asanga is offline Offline
35 posts
since Aug 2010
Sep 1st, 2010
0
Re: How to update a picture
Isnt there anyone who can help me with this issue?? any expert?? Please..
Reputation Points: 10
Solved Threads: 1
Light Poster
sami.asanga is offline Offline
35 posts
since Aug 2010
Sep 1st, 2010
0
Re: How to update a picture
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.
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Sep 1st, 2010
0
Re: How to update a picture
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.
Last edited by Daiva; Sep 1st, 2010 at 3:58 am.
Reputation Points: 14
Solved Threads: 9
Light Poster
Daiva is offline Offline
37 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: For Each Loop with Array Not Quite Working Right
Next Thread in PHP Forum Timeline: Split Array and format with comma as separator





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC