I have this where i have a query to get the teams and filtering them by their league. My problem is that in the the console.log of the following code the data is being shown correctly but in the SELECT statement it's not working as it's not showing anything in the dropdown. When i do it hardcoded the SELECT statement works fine. Any idea what might be the problem. Thanks
Code
$league = '';
if(isset($_POST['selected'])):
$league = $_POST['selected'];
endif;
$home_team = $dbh->prepare("SELECT * FROM teams WHERE competition = :league");
echo "<script>console.log($league)</script>";
$home_team->execute([ ':league' => $league ]);
Fetching Teams
<?php
while ($row = $home_team->fetchAll())
{
$hometeamlogo = $row['logo'];
$hometeamstadium = $row['stadium'];
echo "<option value='data:image/png;base64,".base64_encode( $hometeamlogo )."' data-stadium='$hometeamstadium'>" . $row['team_name'] . "</option>";
}
?>
AJAX Call
$('#input_competition').on('change', function () {
var selectedLeague = $('#input_competition').find(":selected").text();
$.ajax({
url: 'queries/view_fixtures_queries.php',
type: 'POST',
data: {'selected' : selectedLeague},
success: function(data) {
console.log(data);
}
});
});