Problem with phpscript

Discussion in 'PHP' started by libra, Mar 27, 2007.

  1. #1
    In the below script you see a string length counter

    This script is working fine but i have a problem

    When first time i open this page in my browser it show an error in line 2
    (explained in image 2)

    But when u enter the test string the error removed

    I can't remove the 'test' variable
    b'coz i have to work with it

    Can anybody help me to to remove this erro line in the browser


    Image 1
    [​IMG]

    Image 2
    [​IMG]

    Image 3
    [​IMG]
     
    libra, Mar 27, 2007 IP
  2. yourihost

    yourihost Well-Known Member

    Messages:
    1,708
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    115
    #2
    Make it so once you press "click here" it echo the variable , so it isnt there before.
     
    yourihost, Mar 27, 2007 IP
  3. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's a notice, not an error.

    You have to check that the element exists in the array first.

    Instead of:

    $var = $_GET["test"];
    $len = strlen($var);
    PHP:
    You would do:

    if (isset($_GET["test"])) {
       $var = $_GET["test"];
       $len = strlen($var);
    }
    else {
       $var = "";
       $len = 0;
    }
    PHP:
     
    Robert Plank, Mar 27, 2007 IP
  4. libra

    libra Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks

    'isset' in 'if' condition worked

    thanks
     
    libra, Mar 27, 2007 IP
  5. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #5
    Notices are almost 100% useless, you can safely disable them.
     
    Rub3X, Mar 27, 2007 IP