Round Rock / Austin, Texas
Drupal Web Developer

Trouble Getting your 'GET' Variables to Work?

Trouble Getting your 'GET' Variables to Work?

PHP for GET Variables

Always make sure you do some error checking before trying to use the GET variable!

In this example we are passing something like this: http://www.foxwebdevelopment.com?year=2104

In our code we want to validate by using 'isset' before actually trying to use the value. Otherwise php is going to barf and throw and error such as "Notice: Undefined index: .... $GET"

if(isset($_GET['year'])){
     $year = $_GET['year'];
} else {
      $year = '2012';
}
Tags: