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:

    $requete='SELECT titre, id FROM AY_albums';
    $response = $bdd->query($requete);
    while($donnees = $response->fetch(PDO::FETCH_ASSOC)){
        $p = "Nom :".$donnees['titre']." <br />\n";

        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:

        $requete ='SELECT * FROM AY_albums WHERE id=$_GET["id"]';
        $response = $bdd->query($requete);
        $donnees = $response->fetch(PDO::FETCH_ASSOC);
        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!




Your query is not correct

 $requete ='SELECT * FROM AY_albums WHERE id=$_GET["id"]';

Single quote forces everything to be string and won't parse string

 $requete ='SELECT * FROM AY_albums WHERE id='.$_GET["id"];

Use echo "< a href='".$lien."?id=$idIci'>$p";

Query string is getting attached to file name. Both should be separated by ?(question mark)

People are also looking for solutions to the problem: php - sending emails from cron tasks in symfony


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.