Page 1 of 1

Using strings in a URL

Posted: Tue May 13, 2008 3:43 am
by kdidymus
Haylp!

I am designing a family tree website. I have produced a database which currently contains one of my ancestors (for test purposes). Each ancestor has a Unique Reference Number (URN).

http://www.didymus.org.uk/display.php

This works fine because the URN of my ancestor is specified in the body of the PHP by using the line:

$urn = "583";

So when you access the above page, the row with URN 583 is called from the MySQL database and displayed.

What I WANT to be able to do is to make this variable and call data from the MySQL DB dependent on the hyperlink clicked by the user

i.e. http://www.didymus.org.uk/display.php?urn=583

But whatever I do I cannot get it to work. I've tried changing the PHP code to:

$urn = "hlurn"

and using the URL http://www.didymus.org.uk/display.php?hlurn=583

But when I try, the page is blank.

What do I need to do to get this function to work?

Many, MANY thanks for saving what little hair I have left!

Kris Didymus.

Re: Using strings in a URL

Posted: Tue May 13, 2008 3:56 am
by aceconcepts
How are you "GETTING" the url variable?

When you pass a variable via the url you need to "GET" it from within your script (display.php)

Code: Select all

 
//url e.g. http://www.didymus.org.uk/display.php?urn=583
 
//To get urn from the above url you need to do:
   $urn=$_GET['urn'];
 
However, you may want to use some error trapping to ensure integrity:

Code: Select all

 
//url e.g. http://www.didymus.org.uk/display.php?urn=583
 
if(isset($_GET['urn']) && !empty($_GET['urn']))
{
   $urn=$_GET['urn'];
} else {
//msg - no urn passed
}
 
 

Re: Using strings in a URL

Posted: Tue May 13, 2008 6:20 am
by kdidymus
You are a star. It works like a dream. I'm using one of the "For Dummies" books and, as you can probably tell, I'm a complete Dummy.

Will be asking lots more questions as my little project grows!

Thanks again.

KD.

Re: Using strings in a URL

Posted: Tue May 13, 2008 7:35 am
by aceconcepts
Everyone has to start somewhere

Glad it works :D