i m adding an book detail in a page(book_detail.php), when i add book information ,i m also adding offers and addons via iframe( using lightwindow.js) related with that book and i saved their id;s in 2 session array. if someone add 2 addons and 3 offers related to that books, i store those addons_is and offer_id in session and when i fill the all detail regarding that book,on the same time i add addons_is and offer_id in the database in same row. like
book_id|book_name|book_price|book_addons|book_offers|
1 | php | 100 |10,11, | 17,18,19
where 10,11 from table_addon wher开发者_运维技巧e that addon detail is saved and 17,18,19 is from table_offers where offer details are saved
now my question is: if someone add 2 offers and 3 addons with their detail, and does not go to submit that page( means he does not add details of that book) and go back, then how do i delete that addons and offers from both of tables.means i want to reset session array as well as the entry from both of table , if someone comes again to add new book detail.
i can not reset session when use comes first time , because on adding addons via iframe , page refresh automatically, so it is not possible to reset session on page load
In terms of how to delete the database records, look into using transactions with MySQL. The idea is that you:
- Start a transaction
- Execute a series of DML statements (INSERT,UPDATE,DELETE...SELECT is also allowed)
- Commit the transaction (make all changes permanent)
At any point after starting the transaction, you can use ROLLBACK to undo the changes that were made since the transaction was started. However, once the entire transaction is committed (using COMMIT) it is final.
In terms of deleting the session data in PHP, you can just unset it:
unset($_SESSION[varname])
HTH,
-aj
精彩评论