SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    i cannot get mysqli_num_rows to work.

    hi everyone.

    i am trying to use mysqli_num_rows within a php function ( i am using the function to determine whether a user was able to deactivate their account). ult.


    i cannot however seem to get it to work. the result always returns the following error message:


    warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\babysitter-agency.com\cms\db_fns.php on line 51


    i enclose my code below



    PHP Code:

        
    function  deactivate_account($id)

    {    
        
        
    //the global connection. 
        
    global $dbc;
        
            
    $qb "UPDATE users
            SET
            live= '1'            
            
            WHERE 
             user_id = '
    $id ' ";
             
            
    $rb mysqli_query ($dbc$qb); // Run the query.

                     
    $returnrows  =     mysqli_num_rows$rb );
                     
                     if (   
    $returnrows == 1)
                          {
                           return 
    $returnrows;
                          }
                     else 
                     return 
    ''
                  
    }
      
    $account     =    deactivate_account(18); 


    echo 
    "$account"
    thank you for your kind attention.

    warm regards

    Andreea

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,032
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    That error normally means that the query that was last executed has failed. Echo your query and try it direct against the database. Are the field and table names used in the query correct?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you do not pass variable $dbc to the scope within the function deactivate_account. i sugget that you need to do like this

    function deactivate_account($id, $dbc) //this enables to pass the database connection object into the function scope in order to use this connection in $rb = mysqli_query($dbc, $qb);
    warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\babysitter-agency.com\cms\db_fns.php on line 51:::this warning means your conncetion to database is not found so Boolean value 0 returned as a result of no conncetion been passed to the function.

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Easiest and quickest way to debug the issue is to use the following:

    PHP Code:
    $rb mysqli_query ($dbc$qb) or die(mysqli_error($dbc)); 

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    UPDATE queries don't return a result set, they return TRUE if the query ended well.
    Use affected_rows to get the number of affected rows for an UPDATE query.

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Also worth mentioning that TRUE does not mean 'changed a row', it simply means 'did not throw error'. You can get a TRUE result and have modified 0 rows, which is why checking the affected_rows is important.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you to everyone for your kind help and assistance with this query. YOu have all clarified the issues for me.


Bookmarks

Posting Permissions

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