<?php 
require_once '../../includes/session-start.req-inc.php';
include_once '../../includes/ico.html.php';
require_once '../../includes/access-required.html.php';
include_once '../../functions/dbconnect.php';
include_once '../../functions/category-functions.php';
include_once '../../functions/products-functions.php';
include_once '../../functions/utils-function.php';
$categories = getAllCategories();
if (isPostRequest()) {
    $category_id = filter_input(INPUT_POST, 'category_id');
    $product = filter_input(INPUT_POST, 'product');
    $price = filter_input(INPUT_POST, 'price');
    include_once '../../includes/products/uploadCheck.php';
    $errors = array();
    if (!isValidProduct($product)) {
        $errors[] = 'Product is not Valid';
    }
    if (!isValidPrice($price)) {
        $errors[] = 'Price is not Valid';
    }
    if (count($errors) == 0) {
        if (createProduct($category_id, $product, $price, $FN)) {
            $results = 'Product Added';
        } else {
            $results = 'Product was not Added';
        }
    }
}
?>
        
Example #2
0
 //check if the line has exactly 5 comma
 substr_count($value, ",") == 5 ? 1 : die("wrong data format..! unusual amount of comma (,) found on line " . $i);
 $arrayOfColumns = explode(",", trim($value));
 //each row exploded into columns
 //each run of outer foreach will create a value set
 $queryStr .= "(";
 $queryStr .= "'" . $date . "'";
 foreach ($arrayOfColumns as $serial => $item) {
     // $serial: 0 for party, 1 for product, 2 for quantity, 3 for lorry, 4 for cName, 5 for cProduct
     //if data is not valid then the page will not redirect. else the page will be redirected to input page
     switch ($serial) {
         case 0:
             isValidParty($item) ? 1 : die("<strong>Error in row " . $i . ".</strong> Party not valid. " . $item);
             break;
         case 1:
             isValidProduct($item) ? 1 : die("<strong>Error in row " . $i . ".</strong> Product not valid. " . $item);
             break;
         case 2:
             isValidQuantity($item) ? 1 : die("<strong>Error in row " . $i . ".</strong> Quantity not valid. " . $item);
             break;
         case 5:
             isValidChallanProduct($item) ? 1 : die("<strong>Error in row " . $i . ".</strong> Challan Product not valid. " . $item);
             break;
         case 6:
             die("Something wrong in the line " . $item);
             break;
         default:
             break;
     }
     // if all valid then build up the query string......
     $queryStr .= ", '" . $item . "'";