You need to persistently store the data somewhere, e.g. database table(s), which is what was stated in the thread on the other help forum.
I think you are lacking in an overall definition of what you are trying to accomplish. You need to first define the work-flow (steps) needed to accomplish a task. For the tasks of uploading images and allowing comments to be made on each image, the work-flow would be -
A. For a user with an image to upload -
- User sits down at a computer and browses to your web site.
- User selects the image upload navigation link.
- If the user is not already logged in, is prompted to do so.
- User is presented with the image upload form, with input fields for a file, a title/caption, a description, and possibly things like a category select/option menu and a public/private radio button, …
- User enters data in form and submits it.
- Form processing code detects the submitted post method form, trims, and validates all the form data, storing validation errors in an array using the field name as the main array index.
- If the form data passes validation (the array holding the error messages is empty), process the form data. For a file upload, you would move the temporary uploaded file to a permanent location and you would insert a row into a table holding information about uploaded images, with things like the user id of the user who uploaded the file, the filename, and all the other unique/one-time information about the image.
B. For a user who wants to view/comment on images -
- User sits down at a computer and browses to your web site.
- User selects the image view navigation link.
- If the user must be logged in to view any image at all and is not already logged in, is prompted to do so.
- User perhaps uses a search form to narrow down the number of images to view.
- Matching images are displayed, along with any existing comments for each image.
- If the current user has permission to post comments, either a comment link will take them to a comment page or modal window can be opened with a blank comment form.
- User enters data in form and submits it.
- Form processing code detects the submitted post method form, trims, and validates all the form data, storing validation errors in an array using the field name as the main array index.
- If the form data passes validation (the array holding the error messages is empty), process the form data. You would insert a row into a table holding information about image comments, with things like the user id of the user who wrote the comment, the image id (primary index from the table holding the information about the uploaded images), the comment text, and any other unique/one-time information about the comment.
BTW - the only header() redirect you should have in your post method form processing code should be upon successful completion of the form processing code. This will cause a get request for the page, which will prevent the browser from trying to resubmit the form data should the user reload the page or navigate away from and back to the page.