Jump to content

Need some help with the GET method


Gyohdon

Recommended Posts

I currently have a page which redirects to itself, with variables stored in the URL, using the GET method to retrieve them and change the page.However when making this, I found that when no variables were given, the page gave error messages. (Because of this I added '?category=x&order=x' at the end).My question is: How do I check if a GET-variable doesn't exist?

Link to comment
Share on other sites

you have to use isset

if(!isset($_GET['category'])){//get category is not set}else{//get category is set}

you may add more condition depending your need

Link to comment
Share on other sites

Either of these, depending on your needs:if (isset($_GET['category']) ) {// do something}if (!empty($_GET['category']) ) {// do something}Of course, you can change the logic and do something if the query is not set or is empty.

Link to comment
Share on other sites

How do I check if a GET-variable doesn't exist?
i want to add one more thing there is some diffrenece beetwen empty[/empty] and isset.so you have to be cautious for some purpose.$var=0; // or var="";empty($var) will evaulate FALSEwhere as isset($var) will evaulate true
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...