I want to make dynamic search button i have this code but doesnt work it gives me this errorCould not connect to database. Fatal error: Wrong SQL: SELECT * FROM kladilnica WHERE Location = Macedonia AND Uplata = 50 AND Liked = 50 Error: Unknown column 'Macedonia' in 'where clause' in C:\xampp\htdocs\bootstrap\shared.php on line 238
Here is the code
if(isset($_POST['searchBtn'])) {
$selectCountryBox = $_POST['selectCountryBox'];
$filterByBet = $_POST['filterByBet'];
$filterByLikes = $_POST['filterByLikes'];
$filterByPublisher = $_POST['filterByPublisher'];
//$filterByDate = $_POST['filterByDate'];
$searchArr = array();
if($selectCountryBox != "") $searchArr[] = "Location = {$selectCountryBox}";
if($filterByBet != "") $searchArr[] = "Uplata = {$filterByBet}";
if($filterByLikes != "") $searchArr[] = "Liked = {$filterByLikes}";
if($filterByPublisher != "") $searchArr[] = "Username = {$filterByPublisher}";
//if($filterByDate != "") $searchArr[] = "Date = {$filterByDate}";
$searchArr = implode(" AND ", $searchArr);
$query = "SELECT * FROM kladilnica WHERE {$searchArr}";
$result = $conn->query($query);
if($result === false) {
echo "<b>Could not connect to database.</b>";
trigger_error('Wrong SQL: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR);
} else {
echo "YES!";
echo $result;
/*while($row = $result->fetch_assoc()) {
$getCountry = $row["Location"];
}*/
}
}