ianhaney50 Posted October 7, 2014 Share Posted October 7, 2014 Hi I am winning I think I have got the records displayed for the current user logged in so basically they can only see their submitted listings and just working on the edit of them so the current user logged in can update their listing and is all working apart from the update of the images the images are stored by the file name on the database and then gets moved onto the server so the actual images are not stored on the database only the file names are and the images are moved onto the server, hope that makes sense what I can't do at the mo is work out how to update the file names of the images on the database and update on the server I get the following error Notice: Undefined index: photo on line 209 and line 211 the coding for them lines are below $pic1= basename($_FILES['photo']['name'][0]); $pic2= basename($_FILES['photo']['name'][1]); The rest of the coding below that is if(!empty($_FILES['photo']['tmp_name'])) { // Number of uploaded files $num_files = count($_FILES['photo']['tmp_name']); /** loop through the array of files ***/ for($i=0; $i < $num_files;$i++) { // check if there is a file in the array if(!is_uploaded_file($_FILES['photo']['tmp_name'][$i])) { $messages[] = 'No file uploaded'; } else { // move the file to the specified dir if(move_uploaded_file($_FILES['photo']['tmp_name'][$i],$target.'/'.$_FILES['photo']['name'][$i])) { $messages[] = $_FILES['photo']['name'][$i].' uploaded'; } else { // an error message $messages[] = 'Uploading '.$_FILES['photo']['name'][$i].' Failed'; } } } The update query is below // save the data to the database mysql_query("UPDATE privatelistings SET listingtitle='$listingtitle', make='$model', model='$model', exteriorcolour='$exteriorcolour', enginesize='$enginesize', fueltype='$fueltype', yearregistered='$yearregistered', transmission='$transmission', mileage='$mileage', nodoors='$nodoors', bodystyle='$bodystyle', price='$price', photo='$pic1', photo1='$pic2' WHERE id='$id'") or die(mysql_error()); I am going to be updating to mysqli just want to get it working first My HTML form coding is below <form action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div> <strong>Listing Title: *</strong> <input type="text" name="listingtitle" value="<?php echo $listingtitle; ?>"/> <br/> <strong>Make: *</strong> <input type="text" name="make" value="<?php echo $make; ?>"/> <br/> <strong>Model: *</strong> <input type="text" name="model" value="<?php echo $model; ?>"/> <br/> <strong>Exterior Colour: *</strong> <input type="text" name="exteriorcolour" value="<?php echo $exteriorcolour; ?>"/> <br/> <strong>Engine Size: *</strong> <input type="text" name="enginesize" value="<?php echo $enginesize; ?>"/> <br/> <strong>Fuel Type: *</strong> <input type="text" name="fueltype" value="<?php echo $fueltype; ?>"/> <br/> <strong>Year Registered: *</strong> <input type="text" name="yearregistered" value="<?php echo $yearregistered; ?>"/> <br/> <strong>Transmission: *</strong> <input type="text" name="transmission" value="<?php echo $transmission; ?>"/> <br/> <strong>Mileage: *</strong> <input type="text" name="mileage" value="<?php echo $mileage; ?>"/> <br/> <strong>Number of Doors: *</strong> <input type="text" name="nodoors" value="<?php echo $nodoors; ?>"/> <br/> <strong>Body Style: *</strong> <input type="text" name="bodystyle" value="<?php echo $bodystyle; ?>"/> <br/> <strong>Price: *</strong> <input type="text" name="price" value="<?php echo $price; ?>"/> <br/> <strong>Photo One:</strong> <input type='hidden' name='size' value='350000'><input type='file' name='photo[]'> <br> <strong>Photo Two:</strong> <input type='hidden' name='size' value='350000'><input type='file' name='photo[]'> <br> <input type="submit" name="submit" value="Submit"> </div> </form> sorry was not sure what other I need to show, so you guys get the idea? Quote Link to comment https://forums.phpfreaks.com/topic/291496-update-stored-image-filename/ Share on other sites More sharing options...
jcbones Posted October 8, 2014 Share Posted October 8, 2014 I am not sure I understand the question. You want to rename image files that exist on the server? and then change them in the database so they match? If so, there should never be a need to do that. You should be creating a unique image name for each image uploaded. The user never needs to know this name, only the browser. The only thing the user would need to know is the captions, comments, etc.To answer the question explicitly = rename() Quote Link to comment https://forums.phpfreaks.com/topic/291496-update-stored-image-filename/#findComment-1492987 Share on other sites More sharing options...
ianhaney50 Posted October 8, 2014 Author Share Posted October 8, 2014 Hi jcbones Thank you for replying, do appreciate it Yeah sorry that is it, rather than replacing, should be a unique image name for each image so say if they have two current images stored, image1 and image2 then the user updates their listing and uploads the new images imagenew1 and imagenew2, they they should be stored on the database and server instead of image1 and image2, that make sense is it done via the rename link you put just above? Quote Link to comment https://forums.phpfreaks.com/topic/291496-update-stored-image-filename/#findComment-1493001 Share on other sites More sharing options...
ianhaney50 Posted October 8, 2014 Author Share Posted October 8, 2014 what would the query look like as guessing it needs to be UPDATE instead of INSERT INTO so it updates the other text fields as well as storing new images uploaded by the user Quote Link to comment https://forums.phpfreaks.com/topic/291496-update-stored-image-filename/#findComment-1493002 Share on other sites More sharing options...
jcbones Posted October 8, 2014 Share Posted October 8, 2014 What you would need to do is first pull the image names from the database, then save the new images using those same image names. It will overwrite the old images with the new ones, no need to change the database at all. Quote Link to comment https://forums.phpfreaks.com/topic/291496-update-stored-image-filename/#findComment-1493084 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.