Home >Backend Development >PHP Tutorial >Notice: Undefined index: sku in PHP problem solution_PHP tutorial
This is not a bug, but a warning. When using $_GET[] or $_POST[] without adding isset or other judgments, this error will be prompted. The solution suggested by Jones perfectly solves this problem:
/* * 取代$_GET[]获取值 */ function _get($str) { $val = !empty($_GET[$str]) ? $_GET[$str] : null; return $val; } /* * 取代$_POST[]获取值 */ function _post($str) { $val = !empty($_POST[$str]) ? $_POST[$str] : null; return $val; }
When using, the usage is as follows:
/** 设置当前页数 */ $page = _get('page'); $inventory->setCurrentPage($page); /** 计算总页数 */ $sku = _post('sku'); $warehouse = _post('warehouse'); $supplier = _post('supplier');