php - How to continue a Transaction on multiple pages -
i have 3 html forms on 3 different php pages used insert data in 3 different tables.
current process follows:
- user fills first form & click on "next" (data inserted in 1st table in database)
- user fills second form & click "next" (data stored in 2nd table in database)
- user fills third form & click "finish" (data stored in 3rd table in database)
i want:
commit must issued in case when user fills 3 forms & click finish. if user quits/exits on stage before filling 3 forms, data stored in tables should roll-backed.
can use laravel db::transaction
or have other option? please give suggestion.
actually in each steps user can add multiple records in 1 table. example on 3rd step user can add many records in subjects
table wants. use following code save these multiple records in table subjects
:
for($i=1; $i<=input::get('total_subjects'); $i++){ if(input::get('sub_'.$i) != null){ $sd = new subject; $sd->class_detail_id = input::get('class_detail_id'); $sd->subject_id = input::get('sub_'.$i); $sd->status = 'active'; $sd->save(); }
now problem is: how possible store references models of subject
? solution comes mind make transaction , commit
after 3rd step otherwise transaction roll-backed.
why not put form data temp session variable , after completing step 3 insert data session database?
why use method instead?
1) there no trash in database.
2) session auto-cleans after user leaves webpage (willingly or accident).
3) can move freely between steps , info auto-filled or return.
4) 1 connection database - faster website.
5) enables use transactions.
Comments
Post a Comment