php 错误:未定义搜索按钮的索引 [重复]

php error: Undefined index for search button [duplicate]

提问人:Marjolein 提问时间:9/30/2015 更新时间:9/30/2015 访问量:287

问:

我正在尝试为搜索按钮编写代码。但问题是我收到错误:

  • 注意:未定义索引:zoekBedrijf in php/vacatureoverzichtphp.php 在第 12 行
  • 注意:未定义索引:13行php/vacatureoverzichtphp.php中的zoekDatum

我正在尝试将 $_POST 放入一个变量中,以便我可以检查输入是否已填充,如果未填充,则必须显示数据库中的所有数据。我是 php 的新手,以前从未编写过搜索代码。所以可能是我做错了......但我认为这行得通。

您可以在下面找到我的php代码:

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

 //include '../loginHandlerconnect.php';
include('php/loginHandlerconnect.php');

$db = loginHandlerconnect();

$bedrijfzoek = $db->quote($_POST['zoekBedrijf']);      //line 12
$datumzoek = $db->quote($_POST['zoekDatum']);          //line 13

if($bedrijfzoek == null && $datumzoek == null){

       //code for showing the results   

}
if($bedrijfzoek != null){

       //code for showing the results       

}
if($datumzoek != null){

       //code for showing the results   

}
if($bedrijfzoek != null && $datumzoek != null){

       //code for showing the results

}

?>

还有我的html代码:

<form class="form-inline pull-right" role="form" method="POST" action="php/vacatureoverzichtphp.php">
            <div class="form-group">
                <label>Zoeken op: </label>
            </div>
            <div class="form-group">
                <label class="sr-only" for="zoekenBedrijf">Bedrijfsnaam</label>
                <input type="text" class="form-control" name="zoekBedrijf" id="zoekenBedrijf" value="<?php echo (isset($_POST['zoekBedrijf']) ? $_POST['zoekBedrijf'] : ""); ?>" placeholder="Bedrijfsnaam">
            </div>
            <div class="form-group">
                <label>of</label>
            </div>
            <div class="form-group">
                <label class="sr-only" for="zoekenDatum">Datum</label>
                <input type="text" class="form-control" name="zoekDatum" id="zoekenDatum" value="<?php echo (isset($_POST['zoekDatum']) ? $_POST['zoekDatum'] : ""); ?>" placeholder="Datum">
            </div>
            <button type="submit" class="btn btn-default">zoeken</button>
        </form>
        <br><br><br>
        <?php
            include("php/vacatureoverzichtphp.php");
        ?>

有人可以帮助我并告诉我我做错了什么或必须做不同的事情吗?

php html 搜索 搜索引擎 undefined-index

评论


答:

0赞 Amarnasan 9/30/2015 #1

错误是您要求 zoekBedrijf 和 zoekDatum,但字段名称是 zoekenBedrijf 和 zoekenDatum。