+ Post New Thread
Results 1 to 8 of 8
Web Development Thread, Variable passed over url error in Coding and Web Development; I have a php page that I want to pass a variable to on the url as the example Code: ...
  1. #1
    cromertech's Avatar
    Join Date
    Dec 2007
    Location
    Cromer by the coast
    Posts
    731
    Thank Post
    177
    Thanked 109 Times in 97 Posts
    Rep Power
    53

    Variable passed over url error

    I have a php page that I want to pass a variable to on the url as the example

    Code:
     http://server.local/fixtures/display.php?teamid=1
    This works fine if I put a value in for teamid but if I forget it/ omit it for any reason I want the script to die so I tried the following

    Code:
     if (!teamid){
    die ('No variable entered');
    }
    but it kills the code even with the variable in the line.

    How do I do this?

  2. #2
    AJT1's Avatar
    Join Date
    Nov 2007
    Location
    North East
    Posts
    83
    Thank Post
    13
    Thanked 5 Times in 5 Posts
    Rep Power
    15
    How about this:

    if (empty($_GET['teamid'])){
    die ('No variable entered');
    }

  3. #3
    AJT1's Avatar
    Join Date
    Nov 2007
    Location
    North East
    Posts
    83
    Thank Post
    13
    Thanked 5 Times in 5 Posts
    Rep Power
    15
    Although that will count 0 as empty so I tend to do them like this

    if(isset($_GET['teamid'])){
    $teamid= $_GET['teamid'];
    }
    else{
    die ('No variable entered');
    }

  4. Thanks to AJT1 from:

    cromertech (11th July 2011)

  5. #4
    cromertech's Avatar
    Join Date
    Dec 2007
    Location
    Cromer by the coast
    Posts
    731
    Thank Post
    177
    Thanked 109 Times in 97 Posts
    Rep Power
    53
    Thank you that worked perfectly.

  6. #5

    MK-2's Avatar
    Join Date
    Oct 2006
    Location
    Nottingham
    Posts
    3,237
    Thank Post
    149
    Thanked 581 Times in 307 Posts
    Blog Entries
    8
    Rep Power
    199
    what about (i know you've already fixed it)

    if(!isset($_GET["teamid"])) die(no variable set);

    thats what i have used for a ?debug=1 ID

  7. #6

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    240
    Quote Originally Posted by MK-2 View Post
    what about (i know you've already fixed it)

    if(!isset($_GET["teamid"])) die(no variable set);

    thats what i have used for a ?debug=1 ID
    But @cromertech is probably going to want to use $teamid elsewhere in the script so far better move it into an easier to reference variable than $_GET['teamid'] everytime he needs it.

  8. #7

    MK-2's Avatar
    Join Date
    Oct 2006
    Location
    Nottingham
    Posts
    3,237
    Thank Post
    149
    Thanked 581 Times in 307 Posts
    Blog Entries
    8
    Rep Power
    199
    Quote Originally Posted by Hightower View Post
    But @cromertech is probably going to want to use $teamid elsewhere in the script so far better move it into an easier to reference variable than $_GET['teamid'] everytime he needs it.
    fine.....shoot me down......be like that......(cant think of any other sulky quotes, google any you want!)
    i only used the debug one as it gives me access to pages i wouldnt normally see based on my group membership, so it was really only functional once per page, i see what you mean (something else new to learn )

  9. #8

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    240
    Quote Originally Posted by MK-2 View Post
    fine.....shoot me down......be like that......(cant think of any other sulky quotes, google any you want!)
    i only used the debug one as it gives me access to pages i wouldnt normally see based on my group membership, so it was really only functional once per page, i see what you mean (something else new to learn )
    Yep, only pointed it out as I knew you were getting to grips with PHP and thought it was handy to understand why one might choose the first bit of mentioned code over your code

SHARE:
+ Post New Thread

Similar Threads

  1. How can I enable url rewrite/clean url for PHP apps on the EMBC Webserver
    By camel in forum East Midlands Broadband Consortium (EMBC)
    Replies: 3
    Last Post: 15th November 2010, 04:53 PM
  2. VB help - mapping drive using variable
    By mrbios in forum Coding
    Replies: 4
    Last Post: 21st October 2010, 08:41 AM
  3. [Website] PHP variable variables
    By somabc in forum Jokes/Interweb Things
    Replies: 6
    Last Post: 19th October 2010, 01:14 PM
  4. Replies: 3
    Last Post: 11th September 2009, 09:01 AM
  5. Moodle - undefined variable error
    By damienharrison in forum Virtual Learning Platforms
    Replies: 5
    Last Post: 26th September 2007, 10:15 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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