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.
Using strings in a URL
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Using strings in a URL
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)
However, you may want to use some error trapping to ensure integrity:
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'];
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
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.
Will be asking lots more questions as my little project grows!
Thanks again.
KD.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Using strings in a URL
Everyone has to start somewhere
Glad it works
Glad it works