views:

31

answers:

1

Hello,

I have one form on the page for addition and it is related with 2 tables in the database.

Eg. Say i have a table named event and one table named eventphotos. The uploadify plugin of jquery for eventphotos works just fine, however, event is the master table and eventphotos is the child table. Thus when i upload the photo due to asynchronous behaviour of uploadify the photo gets submitted on server but there is no EventId present for this photo which throws exception when i try to insert the photo into evenphotos. I hope you got the idea what the problem is.

I want that when the user clicks on the submit button on the form, the photo uploading process should start and it should only get inserted into database once the master record is inserted into table.

How do i make this happen?

Thanks in advance :)

+3  A: 

One solution: Save the image somewhere in a temorary folder using a random generated name, then send this random name back and insert into your form as hidden field. When the form gets submitted you check if the file still exists and load it.

Another solution: Create a table called "temporary_photos" or similar, insert your picture. And send back the ID of the record and insert it as hidden field in your form. Don't forget timestamps so that you can delete images which have never been used. And delete records if you have saved the event!

sled
The 2nd solution is exactly how I managed this issue. Nice one @sled
jakenoble