Donovan Posted February 6, 2008 Share Posted February 6, 2008 I have been working on a script that is just about finished. One question I have is validating the logic. The script has become bloated and hard to follow. If I wanted to add some validation then what is the best way? I have a table I created and then imported records from a csv file. The csv is from a testing scantron that has exam grades. I want to test the following: Check if already imported Validate UID and compare to Student_ID in the imported table. Check if all Students are assigned to a group. Check if any students are missing from import. Each part of the script works but the logic does not flow. I was thinking about something like this: *Just a rough draft* $Session_ID = $_POST['Session_ID']; //Check if already imported $checked = checkSession($Session_ID); if $checked = 1 { die(); }else{ //Validate UID and compare to Student_ID in the imported table. $checked = checkUID(); if $checked = 1 { die(); }else{ //Check if all Students are assigned to a group. $checked = checkGroup(); if $checked = 1 { die(); }else{ //Check if any students are missing from import. $checked = checkMissingStudents(); if $checked = 1 { die(); } //No errors detected so import grades to grades table. } What is the proper way to trap errors and/or return from a function so that it does not continue until all logic errors are fixed? Quote Link to comment https://forums.phpfreaks.com/topic/89777-validating-logic/ Share on other sites More sharing options...
Donovan Posted February 7, 2008 Author Share Posted February 7, 2008 Could I do something like this? $HasError=FALSE; $Session_ID = $_POST['Session_ID']; //Check if already imported checkSession($Session_ID); if (checkSession($Session_ID) == TRUE) { //Validate UID and compare to Student_ID in the imported table. checkUID(); if (checkUID()==TRUE) { //Check if all Students are assigned to a group. checkGroup() if (checkGroup()==TRUE) { //Check if any students are missing from import. checkMissingStudents(); if (checkMissingStudents()==TRUE) { $HasError=TRUE; //we have missing students } } else { $HasError=TRUE; //we have group problems } } else { $HasError=TRUE; //we have userid problems } else { $HasError=TRUE; //we Session problems } else{ //No errors detected so import grades to grades table. if ($HasError==FALSE) { $sql = ("INSERT INTO blah blah"); } Quote Link to comment https://forums.phpfreaks.com/topic/89777-validating-logic/#findComment-460742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.