Jump to content

Nearly there but.... not quite! switch and Case functions


jimmyborofan

Recommended Posts

right then here goes...

 

After the help I had earlier I have begun to try to pass a value across from one page to another dependiong upon the value, the page displays one thing or another ( I know this is simple stuff but seriously

 

<------------------------NEWBIE!!!!!!!!!!!!!!!!!!!!!

 

see what I mean...)

 

 

okay the code I have so far has a page with four links that show countries

 

when sent to the second page, the page should display the capital.

 

Here is the code:

 

link.html

<html>
<body>
<p><a href="contact.php?$country=UK">The United Kingdom</a></p>

<p> <a href="contact.php?$country=US">The United States</a></p>

<p><a href="contact.php?$country=FR">France</a></p>

<p> <a href="contact.php">Not sure...</a></p>

</body>
</html>

 

 

and this is the page that the values are sent too:

 

capitals.php:



<html>
<body>
<?php
$country = $_GET['$country'];
switch ($country)
{
case 'UK':
$capital = 'London';
break;
case 'US':
$capital = 'Washington';
break;

case 'FR':
$capital = 'Paris';
break;
default:
$capital = 'Unknown';
break;
}
?>

<?=$capital?>
</body>
</html>

 

As other members may see I am trying to transpose from what I know of asp across to php, now absolutley nothing happens!

 

Please could somebody give me some direction or just plainly point out where I have gone wroing then give me a slap on the back of the head!

 

lol

 

Jimmy

All looks good except this:  $country = $_GET['$country'];

use this:

 

$country=$_GET['country'];

 

Also change this:  <?=$capital?>

to:

 

<?php echo $capital; ?>

I'm assuming that's where you wanted it output at.  Also, do not use short tags. 

You diamonds!

 

Thank you its now working and I can finally get on with the rest of the stuff that I need to do!

 

(dont worry though... No doubt when my next assignment comes along I will be back here!)

 

Thanks peeps

 

Jimmy

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.