255) { $product_name_err = "Max size for the product name is 255 characters." . "Yours was " . strlen(trim($_POST["name"])) . " characters long."; } else { $product_name = trim($_POST["name"]); } // DESCRIPTION if (empty(trim($_POST["description"]))) { $description = null; } else if (strlen(trim($_POST["description"])) > 65535) { $description_err = "Your description is too long."; } else { $description = trim($_POST["description"]); } // EXPIRATION DATE if (empty(trim($_POST["date"]))) { $expiration_date = null; } else if (date_format(date_create($_POST["date"]), 'Y-m-d') == $_POST["date"]) { $min_date = date_format(date_create("01/01/1000"), 'Y-m-d'); $max_date = date_format(date_create("12/31/9999"), 'Y-m-d'); if ((trim($_POST["date"]) >= $min_date) && (trim($_POST["date"]) <= $max_date)) { $expiration_date = trim($_POST["date"]); } else { $expiration_date_err = "The date isn't in our correct expiration date range."; } } else { $expiration_date_err = "The date is invalid."; } // CUPBOARD if (empty(trim($_POST["cupboard"]))) { $cupboard = null; } else if (is_numeric(trim($_POST["cupboard"]))) { $cupboard_id = trim($_POST["cupboard"]); if (does_cupboard_exist_from_id($cupboard_id)) { $cupboard = trim($_POST["cupboard"]); } else { $cupboard_err = "Unknown cupboard."; } } else { $cupboard_err = "Cupboard id isn't int."; } // ======================================================================== // ======================================================================== // INSERTION IN DATABASE IF CORRECT // ======================================================================== if (empty($product_name_err) && empty($description_err) && empty($expiration_date_err) && empty($cupboard_err)) { if (!add_product($product_name, $description, $expiration_date, $cupboard_id)) { echo "Error. Something went wrong."; } } else { echo $product_name_err; echo $description_err; echo $expiration_date_err; echo $cupboard_err . $_POST["cupboard"]; } } // ============================================================================= // BUILD CUPBOARD LIST FROM DATABASE // ============================================================================= $cupboard_list = ""; foreach (get_users_cupboards_array() as $row) { $cupboard_list = $cupboard_list . "\n"; } ?> Document
" method="post">