I am trying to construct a query based upon a form consisting of several drop down boxes. I have tried googling around for solutions but haven't been able to get any success and am currently getting 'Databse query failed' and am not sure if this is because my query is constructed wrong or if the form inputs aren't being correctly transferred over to the php file. Any help on this would be amazing as at the moment I am really stuck.
<form action="search.php" method=post>
<select id="dung-name-select" name="dung-select">
<option name="" disabled selected hidden>Name</option>
<option value="*">All</option>
<option value="Black Rock Hold">Black Rock Hold</option>
<option value="Court of Stars">Court of Stars</option>
<option value="Darkheart Thicket">Darkheart Thicket</option>
<option value="Eye of Azshara">Eye of Azshara</option>
<option value="Halls of Valor">Halls of Valor</option>
<option value="Maw of Souls">Maw of Souls</option>
<option value="Neltharions Lair">Neltharions Lair</option>
<option value="The Arcway">The Arcway</option>
<option value="Vault of the Wardens">Vault of the Wardens</option>
</select>
<select id="dung-loc-select" name="loc-select">
<option name="" disabled selected hidden>Location</option>
<option value="*">All</option>
<option value="Valsharah">Valsharah</option>
<option value="Suramar">Suramar</option>
<option value="Azsuna">Azsuna</option>
<option value="Stormheim">Stormheim</option>
<option value="Highmountain">Highmountain</option>
</select>
<select id="dung-rating-select" name="rate-select">
<option name="" disabled selected hidden>Rating</option>
<option value="*">All</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="submit" value="Go">
</form>
<?php
$dungeon = $_POST["dung-select"];
$location = $_POST["loc-select"];
$rate = $_POST["rate-select"];
//Database Query
$query = "SELECT * FROM dungeon where Name = $dungeon and Location = $location and Rating = $rate";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Database query failed.");
}
?>
NB: the php code is in a separate file to the form.
$resultvariable when you dump it? it could be on the on your database credentials is causing the error and please observe proper quotation and SQL case. Read about phpconcatenation.