Can someone tell me why I get this error?

Discussion in 'PHP' started by piniyini, May 5, 2006.

  1. #1
    Notice: Use of undefined constant ResultSet - assumed 'ResultSet'

    http://www.toseef.com/img.php

    I'm trying to use the Y! Image API, although it returns the correct results at the bottom I'm getting the error stated above and don't know why :confused:
     
    piniyini, May 5, 2006 IP
  2. kdb003

    kdb003 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    73
    #2
    those arent actually errors, they are just notices.

    turn off notice reporting in php.ini

    or

    // Report all errors except E_NOTICE
    // This is the default value set in php.ini
    error_reporting(E_ALL ^ E_NOTICE);
    PHP:
    http://us3.php.net/error_reporting
     
    kdb003, May 5, 2006 IP
  3. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #3
    Excellent, sorted! Thanks
     
    piniyini, May 5, 2006 IP
  4. Edmunds

    Edmunds Peon

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Notices are errors, theyare just smaller class errors. Turning off notices in any script is not a very good solution, you should just fix the script instead.

    For example, this notice notified you that you were using an un-initialised variable in your script, which can be potentially dangerous.
     
    Edmunds, May 5, 2006 IP
  5. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #5
    piniyini, May 6, 2006 IP
  6. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #6
    I'm bangin my head against a wall here, can anyone help? Simple solution is to turn off error_reporting but I dont really wanna go down that route ...
     
    piniyini, May 6, 2006 IP
  7. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #7
    Are they variables or just constants? If they are variables, then use $ before the var name.

    Have you defined them anywhere before this line?
     
    vishwaa, May 6, 2006 IP
  8. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #8
    piniyini, May 6, 2006 IP
  9. Edmunds

    Edmunds Peon

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    They aren't constants, they are array element names. HUGE difference.

    If you are writing something like this:
    $var[name]
    Then you are wanting to find the array element , which has the same value as the constant "name".
    As in
    define('name', 'blahblah');
    echo $var[name];
    Code (markup):
    is the same as
    echo $var['blahblah']
    Code (markup):
    If you wish to find, just the element of the array called "name", do
    $var['name'] (notice the apostrophes!)
    Code (markup):

    So, the correct of the above would be
     $title = $phpobj['ResultSet']['Result'][$i]['Title'];
    Code (markup):
     
    Edmunds, May 6, 2006 IP
    piniyini likes this.
  10. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #10
    Nice one Edmunds, that really helped and I've managed to reduce the bulk of the errors.

    Only errors now are along the lines of

    Notice: Undefined index: q in httpdocs/web on line 40

    I think this is something to do with the script needing php5 when my server is using php4, so I will most likely surpress the errors.
     
    piniyini, May 8, 2006 IP
  11. Edmunds

    Edmunds Peon

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Nah, that's gotta do with you either calling a value on array element which doesn't exist.
     
    Edmunds, May 8, 2006 IP
  12. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #12
    If you look at http://www.dasna.com/web you'll notice it says

    Notice: Undefined index: q in /sites/dasna.com/htdocs/web on line 40

    and on line 40 I have

    $q = $_GET["q"];
    PHP:
    Whats the deal here?
     
    piniyini, May 8, 2006 IP
  13. MrSupplier

    MrSupplier Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    you need to check if its available first:

    
    $q = somedefaultvalue;
    if ( isset($_GET["q"]) ){
        # TODO validate q, prevent hacks
        $q = $_GET["q"];
    }
    
    PHP:
     
    MrSupplier, May 8, 2006 IP
  14. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #14
    It happened because 'q' and 'p' are undefined. You need to define these varaibles before using them in your script.

    This will work.
    Replace the line 40 with the below

    if(!isset($_GET['q'])) $q = ''; else $q = $_GET['q'];
    if(!isset($_GET['p'])) $p = 1; else $p = $_GET['p'];

    hope it helps.

    edit: to add the else part
     
    vishwaa, May 8, 2006 IP
  15. Edmunds

    Edmunds Peon

    Messages:
    136
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I find this syntax to be the easiest:

    if (!isset($_GET['q'])) $_GET['q'] = FALSE;
    $q = $_GET['q'];
    
    PHP:
    This is supposedly bad practice because you're not supposed to write to superglobal variables, but I honestly don't care.
    :)
     
    Edmunds, May 9, 2006 IP
  16. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #16
    I think I need to read a PHP book to understand this stuff, thanks for the input guys. I'll be using isset more often thats for sure!
     
    piniyini, May 9, 2006 IP