Jump to content

Recommended Posts

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?

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/89777-validating-logic/
Share on other sites

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");
} 

Link to comment
https://forums.phpfreaks.com/topic/89777-validating-logic/#findComment-460742
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.