nvee Posted January 5, 2010 Share Posted January 5, 2010 Hey Guys I have a edit feature for a simple news script I am writing. The user clicks on a news article under news.php which then takes him to edit_news.php?id=*** (depending on the article he clicked on in news.php edit_news.php then has a simple form (same form used to add news) which has 3 fields, namely header, content and image. Obviously, the fields are already populated with the existing content in the database. I manage to retrieve the content for header and content, but the image field remains empty. From what I understand, due to a security issue, I cannot populate the content for image in a <input type="file"> but there has to be a way to edit the image. All I want is for the image field to atleast default select the image already entered in the database, so that if the user decides to only edit e.g. a spelling mistake, it can still use the existing image, but if the user wants to change the image, they can select a new one with then ammends the image in the database. I guess this is more "how do I" than actual coding related issue, hope someone can help Quote Link to comment https://forums.phpfreaks.com/topic/187228-retrieve-image-value-from-database-for-edit/ Share on other sites More sharing options...
Adam Posted January 5, 2010 Share Posted January 5, 2010 Why not display the image back to the user (best off with a smaller thumbnail version), then maybe using radio buttons ask something along the lines of: [x] Keep this image (preview here) [ ] Upload new image (input file here) Quote Link to comment https://forums.phpfreaks.com/topic/187228-retrieve-image-value-from-database-for-edit/#findComment-988748 Share on other sites More sharing options...
teamatomic Posted January 5, 2010 Share Posted January 5, 2010 You dont want the image itself but the filename displayed, you can show the image but its the filename that will get edited. As for a new image you need to create for the uploading of a file. I'd imagine it wold be the same code you used for the original image to get uploaded. HTH Teamaotmic Quote Link to comment https://forums.phpfreaks.com/topic/187228-retrieve-image-value-from-database-for-edit/#findComment-988772 Share on other sites More sharing options...
nvee Posted January 5, 2010 Author Share Posted January 5, 2010 well i really just want a filename in the field. I have validation which checks for empty fields. The form I use is exactly the same form I use for adding news items, only difference is with edit it retrieves the content from the database and inserts in into the text fields using <input name="img" type="file" value="<?php echo $result["img"]; ?>" /> (where result is the value of the mysql_fetch_array ealier in the script. If I dont have something in the text field, the validation will give an error and say that i need a value within the file field name. All i wanted to do was that the name must be there so that someone can just submit and the filename in the db will work. I however dont think its a bad idea to rather give the user an option if they want to override the file name, that way I can just add one more if else statement and that should do the trick. Keep you up to date Quote Link to comment https://forums.phpfreaks.com/topic/187228-retrieve-image-value-from-database-for-edit/#findComment-988783 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.