Bruno Bruno - 1 month ago 11
MySQL Question

Approach to dealing with multiple image uploads for a single record

I am learning PHP by building a simple real estate management system. I have a form where people can add details of a house and it is added to a table called "properties". I then wanted the ability to add multiple images of the house which will then be shown as a gallery when the house is viewed.

I made a separate table to handle the image paths called "propertyimages". I can link the rows in this table with the property through the ID from the "properties" table. But my question is how can I save the image-paths with the id of the property if the property itself hasn't been saved to the table yet?

In other words, it would be easier if the property is first saved, then adding images since I have the property ID to then save the image paths, but I only have one form so how can I do this at the same time?


This is but one of many approaches to this.

At the top of your add.php file (or whatever you have named it) generate a UUID, assign it to a variable, and within your form have a <input type="hidden" name="id" value="<?=$UUID;?"> that is passed to your process.php file (or whatever you have named it).

As I mentioned other ways of doing it, but if you are just learning as you indicated, this is probably one of the easier ways to handle this.