Example #1
0
            $db->exec($query);
            //redirecting for display of results
            header("Location: ./incidentList.php");
        } catch (Exception $e) {
            //here be your error
            echo "Encountered an exception: " . $e->getMessage();
        }
    } else {
        //if data is NOT ok - show error message and redisplay form
        //create array to catch string values of invalid input
        $badInfo = [];
        //check given input for our failure causing culprit(s)
        badInputCheck($customerID, $badInfo, 'customer ID', $validCustomerID);
        badInputCheck($productCode, $badInfo, 'product code', $validProductCode);
        badInputCheck($title, $badInfo, 'title');
        badInputCheck($description, $badInfo, 'description');
        //create string for display of proper informative error
        $badInfo = join(", ", $badInfo);
        $feedback = "Please enter a valid {$badInfo} and try again";
        //redirecting to form
        include "AddIncidentForm.php";
    }
}
function badInputCheck($inputName, &$failArray, $failString, $otherwiseValid = true)
{
    //if our field is empty going in or not otherwise valid due to optional param
    if (empty($inputName) || $otherwiseValid === false) {
        //push to our target 'error' array a string of our choosing
        array_push($failArray, $failString);
    }
}
Example #2
0
            //redirecting for display of results
            include "AddProductForm.php";
            header("Location: ./ProductList.php");
        } catch (Exception $e) {
            //here be your error
            echo "Encountered an exception: " . $e->getMessage();
        }
    } else {
        //if data is NOT ok - show error message and redisplay form
        //create array to catch string values of invalid input
        $badInfo = [];
        //check given input for our failure causing culprit(s)
        badInputCheck($code, $badInfo, 'code', $validCode);
        badInputCheck($name, $badInfo, 'name');
        badInputCheck($version, $badInfo, 'version', $validVersion);
        badInputCheck($releaseDate, $badInfo, 'release date', $validDate);
        //create string for display of proper informative error
        $badInfo = join(", ", $badInfo);
        $feedback = "Please enter a valid product {$badInfo} and try again";
        //redirecting to form
        include "AddProductForm.php";
    }
}
function badInputCheck($inputName, &$failArray, $failString, $otherwiseValid = true)
{
    //if our field is empty going in or not otherwise valid due to optional param
    if (empty($inputName) || $otherwiseValid === false) {
        //push to our target 'error' array a string of our choosing
        array_push($failArray, $failString);
    }
}