Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Can't get URL Parameter to work.

    Using the link index.php?id=1 will work with the code bellow

    PHP Code:
    if(isset($_GET['id']) && $_GET['id'] === '1') {

    $url_parameter_id1 $_REQUEST['id'];  //REQUEST's parameter's from URL e.g id=?

    PHP CODE HERE


    However if i try index.php?id=12345 I just get the index.php page, how do i get it to accept id=12345 is a valid link and then use the parameter from the id to do something (e.g use it to refrence something in a database labled 12345)

  • #2
    New Coder
    Join Date
    Jul 2009
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I think i figured it out .

    PHP Code:

    if(isset($_GET['id']) && !empty( $_GET['id'] ) ) {

    $url_parameter_id1 $_REQUEST['id'];  //REQUEST's parameter's from URL e.g id=?

    PHP CODE HERE


    I'd still like to know if this is correct way or if there is another way.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You could stick with $_GET but it makes no real difference:

    PHP Code:
    if (isset($_GET['id']) && !empty( $_GET['id'] ) ) { 

        
    $url_parameter_id1 $_GET['id'];  // parameter's from URL e.g id=? 

        
    PHP CODE HERE 


    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    845
    Thanks
    15
    Thanked 10 Times in 10 Posts
    I typically use the following:
    PHP Code:
    if(!empty($_GET['id']) && is_numeric($_GET['id'])) {

    $url_parameter_id1 $_GET['id'];  //GET id query from URL (e.g id=?)

    PHP CODE HERE


    Which always works for me.
    Last edited by dniwebdesign; 11-11-2012 at 07:37 PM.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •