Scenario:
I am populating a dropdown menu with data from MySQL database. Upon clicking submit button, script should take the user to the results page and show data based on their selection.
Problem:
User selection is not able to POST to next page for the query. When I hard code an option in that matches one of the dropdown options, the query works fine.
-- This is the dropdown --
<div class = "servicelinesearchbox">
<div class="servicelinesearchbar">
<form class="form-inline" method="post" action="search_by_service_line.php">
<select name="service_lines" id ="service_lines" form="service_line_form">
<option value = "">---SELECT A SERVICE LINE---</option>
// THIS OPTION ADDED FOR TESTING, DOES WORK AND POPULATE DATA ON NEXT PAGE --
<option value = "Architectural">Architectural</option>
<?php
$sql = "SELECT service_lines FROM service_lines ORDER BY service_lines";
$db = mysqli_query($conn, $sql);
while ( $d=mysqli_fetch_assoc($db)) {
echo "<option value='{".$d['service_lines']."}'>".$d['service_lines']."</option>";
}
?>
</select>
<button type="submit" name="save" class="btn btn-primary">SEARCH</button>
</form>
</div>
</div>
-- This is the part of the results page that uses POST data to run the query --
<?php
include "config.php";
if (isset($_POST["save"])> 0) {
$service_lines = htmlspecialchars($_POST['service_lines']);
$sql = "SELECT * FROM subconsultants WHERE service_lines LIKE '$service_lines'";
$result = mysqli_query($conn, $sql);
}
?>
View Source
?{}
around the values?value='{".$d['service_lines']."}'
value = "Architectural"
, so I think that's why it works and the dynamic ones don't. Get rid of them.