The managing of the success variable is really confusing... Looks like you're initializing it here, and then modifying it while processing item_list later... At the end, looks like you're using success to track if there is any row added to any table. Is it right? Looks like this success variable indeed could be avoided, and just check if there is information in the tables before printing them...