php - when echoing information about a mysql table as a link, and sending information with the link to be retrieved in another page using $_GET not working
In my mysql table I have the primary key column as "id", I want to echo the name of the album (stored as "titre" in mysql) as a link, and in the link include the id number, so the user can access all the information about the album in the link page and modify it. So I know it should look something like this to echo a link and include the id which I retrieved already from mysql:
echo <a href='$link&id=$id'>Link</a>
but can't figure out the correct way of writing it so that &id isn't either disregarded or sent as part of the string.
Here is my php code:
<?php
$requete='SELECT titre, id FROM AY_albums';
$response = $bdd->query($requete);
while($donnees = $response->fetch(PDO::FETCH_ASSOC)){
$p = "Nom :".$donnees['titre']." <br />\n";
$idIci=$donnees['id'];
$lien="modifierAlbumAdmin.php";
echo "<a href='$lien'&id=$idIci>$p</a>";
} ?>
And this is the code I have to retrieve it on the page the link leads to:
<?php
if(isset($_GET["id"])){
$requete ='SELECT * FROM AY_albums WHERE id=$_GET["id"]';
$response = $bdd->query($requete);
$donnees = $response->fetch(PDO::FETCH_ASSOC);
$titre=$donnees['titre'];
print "yes";
}
?>
I added a print statement to see if it enters the if statement and it doesn't even enter. Can anyone help? Thanks!
Answer
Solution:
Your query is not correct
Single quote forces everything to be string and won't parse string
Use echo "< a href='".$lien."?id=$idIci'>$p";
Query string is getting attached to file name. Both should be separated by ?(question mark)