cromertech Posted July 11, 2011 Posted July 11, 2011 I have a php page that I want to pass a variable to on the url as the example 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 if (!teamid){ die ('No variable entered'); } but it kills the code even with the variable in the line. How do I do this?
AJT1 Posted July 11, 2011 Posted July 11, 2011 How about this: if (empty($_GET['teamid'])){ die ('No variable entered'); }
AJT1 Posted July 11, 2011 Posted July 11, 2011 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'); } 1
MK-2 Posted July 14, 2011 Posted July 14, 2011 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
Hightower Posted July 14, 2011 Posted July 14, 2011 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.
MK-2 Posted July 14, 2011 Posted July 14, 2011 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 )
Hightower Posted July 14, 2011 Posted July 14, 2011 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now