I'm trying to extract an id from get-albums-genres.php?gid=".$id." using $_GET and it gives me undefined!
I fetched data for music genres in an array after running an SQL query to extract data from my genre table
$dbcursor = $db->query("
SELECT *
FROM GENRES_TBL
ORDER BY ID
");
$genres = [];
while($takegenre = $dbcursor->fetch_object()) $genres[] = $takegenre;
After this I created a html table containing <a tags with hyperlinks for each genre using foreach loop.
<?php
foreach($genres as $gs)
{
$id = $gs->ID;
echo "
<a class='gentons' href='get-albums-genres.php?gid=".$id."'>".$gs->GENRE."</a>";
}
?>
</table>
With these hyperlinks I want to show table of all albums from selected genre. In order to do that i plan to extract the id from the href and than use it in an SQL query to connect the albums genre id to the genres ids, BUT in the php file for getting the albums when declaring the variable and using $_GET to extract the id it gives me undefined value.
$genre_id = $_GET['gid'];
echo"$genre_id"; //undefined
if(isset ($_GET['gid'])){
echo"yes";
}else{
echo"no";
} //yes
The Javascript code with the event is
$(document).on('click', 'a.gentons', function(e)
{
$.get('get-albums-genres.php?gid=' + $('input[name="gid"]').val(),
function(data)
{
$('#albums-list').html(data);
});
return false;
})
It's strange because i did exactly the same in another php file where i input name or best-song of an artist and find and show all his albums and i have no problems with the $_GET method there. I also don't understand why when i hover my cursor over the hyperlinks for the genres it show the link and the corresponding id, but when i try to extract it there is a problem