Please help me with the global variable GET.

On the index.php page there is a list of songs. Next to each song there is a link to download. When I click on the link, I get to the template, which will be the song name, group, picture, etc. which are taken from a variable, and in the line should be added " / shablon.php? group-song" instead of " / index.php". Here it is. But " / shablon.php? Group-song" is not displayed. Only " / shablon.php?" Is displayed. What am I doing wrong?

//index.php <!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> Группа1 - Песня1 <a href="shablon.php<? echo "?" . $SongID["a1"]; ?>">Скачать</a><br> Группа2 - Песня2 <a href="shablon.php<? echo "?" . $SongID["a2"]; ?>">Скачать</a><br> Группа3 - Песня3 <a href="shablon.php<? echo "?" . $SongID["a3"]; ?>">Скачать</a><br> <?php // Делаю многомерные массивы в которых хранятся песни $SongID["a1"] = "Группа1-Песня1"; $SongID["a2"] = "Группа2-Песня2"; $SongID["a3"] = "Группа3-Песня3"; ?> </body> </html> //shablon.php <!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> Группа1 - Песня1<br> Группа2 - Песня2<br> Группа3 - Песня3<br> </body> </html> 

    1 answer 1

    1. Why is an array of songs declared after use? Those. when creating an array reference yet, fill in after the "?" nothing. Try transferring array initialization above link building.

    2. Why transfer through $ _GET produce as "?песня" ? I thought something was necessary: "?name=песня" , i.e. need to redo the lines:

      Группа1 - Песня1 <a href="shablon.php?name=<? echo $SongID['a1']; ?>">Скачать</a><br>

    3. Do you use global variables or something? I even forgot how to use them, but something seems that the template displays only

      Download <a href="files/a1.rar"></a>

    Once you pass a parameter, why not use it?

     Скачать `<a href="files/a1.rar"><?php echo $_REQUEST['name']; ?></a>` 

    $ _REQUEST used to enable parameters to be passed not only GET ом, но и POST .

    • 1. Transferred arrays above links and everything earned. 2. I don’t want to add more to the lines (I’m talking about "name"). 3. Output. Then fill the page. 4. That is, in my case should be $ _REQUEST ['a1'] instead of $ SongID ["a1"]? - gm-111
    • in your case it will be $ _SERVER ["QUERY_STRING"] how does the server know that this is a1 ??? that's why they offered you a name or something like that - thunder
    • @ gm-111, you can not add if you configure the RewriteRule in .htaccess, i.e. it will automatically lead to the desired form (ie, to? name = songName), but it will be displayed for the user, for example, as (or, better, / songName - the main thing is to process the parameters correctly) - BOPOH
    • Oh, and I like it better. But too difficult for me, since I am still learning. But note, thank you. - gm-111