www.webdeveloper.com
Results 1 to 10 of 10

Thread: Code working fine but generating notices

  1. #1
    Join Date
    Feb 2012
    Posts
    102

    Question Code working fine but generating notices

    Hello Everyone,

    I am having an issue that I just can not figure out. I have my error handling set up to send me an email when errors happen. Recently, my website has been working just fine but I am receiving emails with errors such as:

    mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given

    and

    Undefined variable: GET

    I do not understand why I would be getting an error on the mysqli_fetch_array() as the information I am selecting is being selected as used in the script. Here is the code that I am receiving the errors from:

    PHP Code:
    if (isset($_GET['hrid']) && is_numeric($_GET['hrid'])) {
            
    $hrid $_GET['hrid'];
        }else{
            
    $hridFALSE;
        }


    $q "Select * FROM hotel_reviews WHERE hr_id=$hrid";
    $r mysqli_query($dbc$q);
    $review mysqli_fetch_array($rMYSQLI_ASSOC); 
    If anyone has any suggestions or ideas as to why I keep getting these notices that would be great.

    Thanks for all your help.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,224
    It means your query failed (in the sense that MySQL could not parse/process it at all), so $r is a Boolean false instead of a mysqli result resource/object.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2012
    Posts
    102
    Quote Originally Posted by NogDog View Post
    It means your query failed (in the sense that MySQL could not parse/process it at all), so $r is a Boolean false instead of a mysqli result resource/object.
    That doesnt make sense though as the page that the query is on is using the information from that query and working just fine. Wouldn't the page not load the information being retrieved from the database if the query was failing?

    For example here is the link to a page on the website that this error is happening:

    http://www.top-ten-travel-list.com/hr.php?hrid=23

    If you replace the hrid=23 with say a letter or leave it blank the page still loads but it loads without the information from the query so if the query was failing I would assume it would look like if the page was requested using:

    http://www.top-ten-travel-list.com/hr.php?hrid=E

    What I cant figure out is why I am getting the error if the information being requested from the database by that query is being retrieved and used on the page.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,224
    First, let's make sure that's the line where it's failing: is that the line mentioned in the error message?

    If so, let's find why it's failing:
    PHP Code:
    $q "Select * FROM hotel_reviews WHERE hr_id=$hrid";
    $r mysqli_query($dbc$q); 
    if(
    $r == false) {
      die(
    "<pre>Select failed: ".mysqli_error($dbc)."\n$q</pre>");

    Later on you can turn that die() into something more graceful that logs the error and doesn't just splatter debug info across the screen.

    Also, you should be filtering $hrid to prevent SQL injection errors (or perhaps better yet make use of MySQLi's ability to use prepared statements so that you don't have to worry about that). At the very least, you could just cast it to integer before using it in your query (assuming it's supposed to be an integer?).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Feb 2012
    Posts
    102
    I added your line and it didnt show any errors on the screen and that is why I am so confused. That line is mentioned in the error message and it is the only spot on the page where I query the database. Also, I am checking to make sure that $hrid is numeric to prevent against SQL.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,224
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Feb 2012
    Posts
    102
    Quote Originally Posted by NogDog View Post
    That url wouldnt be used on the site unless it is manually changed. There will always be hrid= and some number, which when you put that in it works. Of course there would be an error if there was no $_GET value as that is what the query uses to search the database.

    I am recieving the errors even when there is a $_GET value but they are notices not errors that stop the script.
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,224
    Just noticed this:
    Undefined variable: GET
    Do you have a $GET somewhere that should be $_GET ?

    As far as that MySQLi error, that should not be a notice, but a "real" error, as far as I know.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Feb 2012
    Posts
    102
    I know that is why it is throwing me off. Ususally, if I have an issue with my sql statement I am not getting any information from my database and the page will not load correctly. I keep getting emails with these notices in them but the pages load just fine. Again, here is the code I am using if anyone can find any problems with it please help me out.

    PHP Code:
    if (isset($_GET['hrid']) && is_numeric($_GET['hrid'])) {
            
    $hrid $_GET['hrid'];
        }else{
            
    $hridFALSE;
        }


    $q "Select gen_description, page_title FROM hotel_reviews WHERE hr_id=$hrid";
    $r mysqli_query($dbc$q);
    $page_info = @mysqli_fetch_assoc($r); 
    Owner of Reality TV Addict
    Publisher of Strategies for Stretching Your Income (ebook)
    CEO and Founder of Sport Directions
    Follow me at @RealityTV_Forum

  10. #10
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    I am not claiming to be pro with php here but i recently had a problem with an error I could not figure out and it was a gif loading image that was not in my image folder. the form was trying to load.

    when you look at your inspect element resources there is a arrows.png file missing. if an image is missing and the page takes it as an error even though it doesn't effect the functionality of the site could that be the reason your getting emails?

    and the console does say failed to load resource... 404 not found... could be the arrows.png file not displaying

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles