berridgeab Posted February 18, 2010 Share Posted February 18, 2010 Hi Not a problem with Code, just after a more general consensus on wether I should be doing so much error checking. When building scripts, should you (I know the answer is yes in practice), check for every conceivable error that could theoretically occur in your code? An example would be good. Im creating a database (MySQL) which has a transaction Table and a customer table. The user raises a new transaction by clicking a link and any transaction ID created is remembered in the session data. My code does the following to create the transaction ID - 1. Clear any old SESSION variables relating to previous Transactions. 2. Attempt to create the transaction ID in MySQL using an INSERT Statement. 3. Check that the INSERT statement was successful, if answer is no, show error. 4. If no Error on 3, then check that I can actually find the transaction in a SELECT statement, if error with statement, or rowcount returns 0, then show error. 5. If no Error on 4, then check that the user hasn't somehow created more than 1 record (hitting the submit button more than once, etc), if rowcount more than 1, then show error. 6. Finally, after checking all of the above, I can confirm that it was successful, get the transaction ID (Its an auto update field) and store it in the session as transactionID. Customer clicks on a link to gather the customer information for the Customer Table. Before I even show them the customer information form, I check - 1. Clear any old SESSION variables relating to previous Customers. 2. Check that there is a transaction ID set in the session and that it is numeric, if not then show Error. 3. If there was no error on 2, check that the transaction ID still exists in the database, if not then show error. 4. If there was no error on 3, check that the transaction ID has no customer ID already associated to it, if it has then show error. 5. Finally after confirming that the transaction exists, and it has no other customer information tied to it, allow customer to fill in the information needed for the Customer Table. Then When they press submit and I go to insert the Customer Data into MySQL I check all of the above again. Am I being too extreme or should I be accounting for every possible error, no matter how remote it could occur? Link to comment https://forums.phpfreaks.com/topic/192504-general-error-capture-question/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.