0

I am trying to write code for a search button. But the problem is that I get the errors:

  • Notice: Undefined index: zoekBedrijf in php/vacatureoverzichtphp.php on line 12
  • Notice: Undefined index: zoekDatum in php/vacatureoverzichtphp.php on line 13

I'm trying to get the $_POST into a variable so I can check if the input is filled or not and if its not filled it has to show all the data from the database. I am new to php and have never coded a search before. So it can be that I am doing it all wrong.... But I thought that this would work.

Below you can find my php code:

<?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

}

?>

And my html code:

<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");
        ?>

Can someone please help me and tell me what I am doing wrong or have to do different?

Marjolein
  • 193
  • 1
  • 12

1 Answers1

0

The error is you're asking for zoekBedrijf and zoekDatum but the field names are zoekenBedrijf and zoekenDatum.

Amarnasan
  • 14,939
  • 5
  • 33
  • 37