开发者

error: Notice: Undefined index: fk

can someone assist me with fixing the error i'm receiving.

$search_key = '';
/*if(isset($_POST) && ($_POST["fk"])!=NULL){
    $search_key = $_POST["fk"];
}elseif(isset($_GET) && ($_GET["fk"]!=NULL)){
    $search_key = $_GET["fk"];
}
*/

if(!isset($_POST["fk"])){
    $search_key = $_POST['fk'];
}elseif(isset($_GET["fk"])){
    $search_开发者_如何学Pythonkey = $_GET["fk"];
}


You're testing for NOT isset $_POST["fk"]

if(isset($_POST["fk"])){ 
    $search_key = $_POST['fk'];


You have a !isset in the first line of the code below

if(!isset($_POST["fk"])){
    $search_key = $_POST['fk'];
}elseif(isset($_GET["fk"])){
    $search_key = $_GET["fk"];
}

So if it $_POST["fk"] is not set, it will try to read it. Hence the error message. Just use isset instead of !isset.

Just a little side-note: if you want to have the value from either a $_POST or $_GET, you could simply use $_REQUEST['fk']; as $_REQUEST holds the values merged from $_COOKIE, $_POST and $_GET (order depends on your PHP configuration)


if(array_key_exists("fk",$_POST)){
$search_key = $_POST['fk'];
}elseif(array_key_exists("fk",$_GET)){
$search_key = $_GET["fk"];
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜