Sending data via Link (POST or GET)

Asked

Viewed 1,331 times

2

Good morning my dear, I’m new around here...

First of all, I want to point out that I have read the topics that exist in this forum and I could not solve my problem!

My problem is to send only the database id from one PHP page to another that will select through that id and display all database data related to the id sent. I want to do it through a link, and I’m not getting it.

<h2>
    <font size="5">
        <a href="mostrar.php" target="_blanck">
            <?=$linha['titulo']?>
        </a>
    </font>
</h2>

The idea is to send the id through this line of code there.

  • 1

    You must use something like href="mostrar.php?id=<?= $linha['id'] ?>".

  • This line is my link, IE, it shows the description of the link and would have to send the id theoretically, however I can not show this my id on the page. <?=$line['title']? > would be the description of my link...

  • There is such a thing: target="_blanck"? Would not be target="_blank"?

  • Typo error buddy, other than that some help ?

1 answer

2


Via POST you will have to make a form.

Via GET just send the id at the end of the url.

<a href="mostrar.php?id=<?=$linha['id']?>" target="_blank"><?=$linha['titulo']?></a>

The url looks like this:

mostrar.php?id=5

In the archive mostrar.php you wear it like this:

$id = $_GET['id'];

But it’s interesting before you check whether the $_GET['id'] really exists:

if (isset($_GET['id'])) {
  $id = $_GET['id'];
}
  • It worked out, buddy, thank you very much :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.