-6

我试图避免未定义的索引。我也使用过 isset,但我无法获得预期的结果。

<body>

    <FORM NAME ="form1" METHOD ="POST" ACTION = "test.php">

<INPUT NAME = "search" size="74">
<INPUT TYPE = "Submit" Name = "SearchButton" VALUE = "Search">
</FORM> 

<?php  
    $search =  isset($_POST['search']);
    //$search = $_POST['search'];
if (!isset($_GET[$search])) {
    // category isn't set
    echo 'not set';

} 
 else {

    echo 'set';
}
?>   

4

2 回答 2

1

我想你想要

$search =  isset($_POST['search']) ? $_POST['search']  : 'some default';      
$search =  isset($_GET['search']) ? $_GET['search']  : 'some default';
于 2012-11-24T19:29:49.237 回答
0

当您执行 $_GET[$search] 时,这将评估为 $_GET[0] 或 $_GET[1],具体取决于参数 'search' 是否设置为 post 变量。我想你会需要类似的东西

if( isset($_POST['search']) ) {
  //do something with the variable
}
于 2012-11-24T19:32:09.757 回答