I made 2 populated selectmenu's to make queries to my sql database. The first option-tags of all select menu's have value="" Now everything works fine when I do select options of all 2 selectmenu's. But If I don't choose 1 or more options, the query doesn't work.
One of the select menu's:
<select name="titel" id="titel" value="">
<option value="">Selecteer</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['titel'].'">'.$row['titel'].'</option>';
}
}else{
echo '<option value="">Language not available</option>';
}
?>
</select>
2nd page (search.php):
<?php
//load database connection
$host = "localhost";
$user = "...";
$password = "...";
$database_name = "...";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
// Search from MySQL database table
$titel=$_POST['titel'];
$version=$_POST['version'];
$query = $pdo->prepare("SELECT DISTINCT * FROM Library where titel = ? AND version = ?");
$query->bindValue(1, $titel, PDO::PARAM_STR);
$query->bindValue(2, $version, PDO::PARAM_STR);
$query->execute();