Jump to content

Recommended Posts

Posted

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?

Posted

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');

}

  • Thanks 1
Posted

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

Posted
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.

Posted
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 :))

Posted
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 :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...