PHP Variables

Discussion in 'Web Design & Coding' started by Jason2k1, Mar 22, 2003.

  1. Jason2k1

    Jason2k1 Guest

    I use php variables passed from page to page by the query string at the end of the url. does anyone know of the code that will declare a default value to a variable if one is not present in the query string?

    Thanks in Advance

    Jason
     
  2. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    The default value will be 0, "" or false depending on use. Using non-existant variables in PHP is not a problem.

    The only thing might be if PHP is set to print out notices. Make sure the error reporting line in php.ini looks like:
    error_reporting = E_ALL & ~E_NOTICE

    Or you could do:
    PHP:
    if(!isset($varname)){
         
    $varname 0      // Or whatever you want to initialize with.
    }
     
  3. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    Can also do somethin like

    PHP:
    $var$_GET["urlstring"];
    if (isset(
    $var) ==0/*i.e. if no value in $var*/
    {
        
    $var1/*then set it to 1 (or whatever default)*/
    }