Pandareen Posted January 4, 2012 Share Posted January 4, 2012 I've managed to insert an image in my database, but when i upload a second picture it replaces the first!What should i do? Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/ Share on other sites More sharing options...
SergeiSS Posted January 4, 2012 Share Posted January 4, 2012 Another question: what do you like to get? Do you like to have 2 images in the DB (and then maybe 3 and more) or something else? Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304272 Share on other sites More sharing options...
Pandareen Posted January 4, 2012 Author Share Posted January 4, 2012 yes, i want to get more, for each ID i like to get 1 image Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304274 Share on other sites More sharing options...
SergeiSS Posted January 4, 2012 Share Posted January 4, 2012 Show you code. How do you insert these images. Otherwise it's impossible to say what is wrong. Maybe you use UPDATE instead of INSERT? Or, maybe, you set just one name for all images that you are load? Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304276 Share on other sites More sharing options...
Phpfr3ak Posted January 4, 2012 Share Posted January 4, 2012 Yea, use UPDATE instead of INSERT Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304279 Share on other sites More sharing options...
Pandareen Posted January 4, 2012 Author Share Posted January 4, 2012 or not: here it is: mysql_query( "INSERT INTO `softmarket`.`internet_securitate` (`internet_securitateID`, `nume_produs`, `descriere`, `versiune`,`poza`, `pret`, `disponibilitate_produs`) VALUES ('', '$_POST[titlu]', '$_POST[descriere]', '$_POST[versiune]', '$foto', '$_POST[pret]', '$_POST[disponibilitate]');"); mysql_query("INSERT `softmarket`.`internet_securitate` SET `val`=$foto WHERE `internet_securitate`.`internet_securitateID` = ;"); function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['foto']['name']) ; $ran2 = $poza."."; $target = "../images/"; $target = $target . $ran2.$ext; if(move_uploaded_file($_FILES['foto']['tmp_name'], $target)) { echo "The file has been uploaded as ".$ran2.$ext; } else { echo "Sorry, there was a problem uploading your file."; } header('Location: succes.php'); mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304280 Share on other sites More sharing options...
SergeiSS Posted January 4, 2012 Share Posted January 4, 2012 What are you doing? 1. Save info from POST array. 2. Save loaded file but don't save info about this file into DB! 3. Don't let a user read info "The file has been uploaded as ".$ran2.$ext; Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304285 Share on other sites More sharing options...
Pandareen Posted January 4, 2012 Author Share Posted January 4, 2012 Ok then, can u help me in this case? please Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304287 Share on other sites More sharing options...
SergeiSS Posted January 4, 2012 Share Posted January 4, 2012 First of all you need to save image by move_uploaded_file() and then, on success, save info into DB. I hope that you know the structure of your DB. Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304292 Share on other sites More sharing options...
Pandareen Posted January 4, 2012 Author Share Posted January 4, 2012 like this? $target_path = "images/"; $target_path = $target_path . basename( $_FILES['foto']['name']); if(move_uploaded_file($_FILES['foto']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['foto']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } i don't know how to rename it :-s Quote Link to comment https://forums.phpfreaks.com/topic/254363-image-replace/#findComment-1304295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.