0

I am a PHP beginner and really need your help.

Ok lets try to make it easy.

I have 2 pages:

1) A index.php page with 4 different buttons:

-Paris

-Nice

-Bordeaux

-Lyon

2) A details.php page with a title and description.

What I want to do:

In index.php, when I click "Paris", i want to load the details.php page with the description of "Paris" that I have on the database.

In index.php, when I click "Nice", i want to load the details.php page with the description of "Nice" that I have on the database.

etc...

I know the form method POST technique to pass information but in this case it is not a form, just different buttons to load specific content from the database in an other page.

I hope I am clear enough.

Waiting for you answers !

Thanks for the reading.

Chloé

Chloé
  • 61
  • 3

3 Answers3

2

Switch is better, and don't forget security

index.php

<a href="details.php?t=paris"><button>Paris</button></a>
<a href="details.php?t=nice"><button>Nice</button></a>
<a href="details.php?t=bordeaux"><button>Bordeaux</button></a>
<a href="details.php?t=lyon"><button>Lyon</button></a>

details.php

<?php
if(!empty($_GET["t"]))
{
    $t = htmlentities($_GET["t"]);
    switch($t)
    {
        case "paris":
            $title = "Detail of $t";
            $text = "...";
            break;
        case "nice":
            $title "Detail of $t";
            $text = "...";
            break;
        case "bordeaux":
            $title "Detail of $t";
            $text = "...";
            break;
        case "lyon":
            $title "Detail of $t";
            $text = "...";
            break;
        default:
            $title = "You asked $t, but is an unknown town in our database";
            $text = "";
    }
}
?>

in head section

<html>
    <head>
    <?php echo "<title>$title</title>"; ?>
    </head>

in body section

    <body>
        <?php echo "$text"; ?>
    </body>

Note: Also, you can try to use a templating engine, to simplify the clarity and mix (php+html)

Look for my example here : Quitting Smarty to do it manually

Community
  • 1
  • 1
MTroy
  • 897
  • 9
  • 20
0

You can use $_GET requests. In page 1 make links like http://example.com?name=paris

And in page 2 you can use: $name = $_GET['name'];

for multiple values devide them with a &. example: http://example.com?page=paris&limit=100&category=airports

RFLdev
  • 186
  • 9
0

index.php

<html>
<body>
<a href="details.php?t=paris"><button>Paris</button></a>
<a href="details.php?t=nice"><button>Nice</button></a>
<a href="details.php?t=bordeaux"><button>Bordeaux</button></a>
<a href="details.php?t=lyon"><button>Lyon</button></a>
</body>
</html>

details.php

<?php
if(isset($_GET["t"]))
{
    if($_GET["t"]=="paris")
    {echo "Desc of Paris";}
    else if($_GET["t"]=="nice")
    {echo "Desc of Nice";}
    else if($_GET["t"]=="bordeaux")
    {echo "Desc of Bordeaux";}
    else if($_GET["t"]=="lyon")
    {echo "Desc of Lyon";}
    else{echo "Invalid Title!";}
}
else{echo "no get value found!";}
?>
Manikiran
  • 2,618
  • 1
  • 23
  • 39