+ Reply to Thread
Results 1 to 8 of 8

Thread: Supplied Argument not valid

  1. #1
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Supplied Argument not valid

    a classmate of mine ask me why is her syntax giving her an error:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in line 103

    here's her code: (i tried to help but it seems that we we're just in the same level )

    PHP Code:
    function check_user($user,$pass)
        {

            if (
    $this->is_checked($user) && $this->is_checked($user) )
            {
                
    $this->connect();
                
    $query "select emp_auth.user_id FROM emp_auth, emp_users WHERE emp_auth.user_id = emp_users.user_id AND emp_auth.passcode = " $pass " AND emp_users.user_name = \"" $user "\";";

                
    $result mysql_query($query);
                
    $num mysql_num_rows($result); //line 103          
                
    mysql_close();
                
                if (
    $num == 1)
                    return 
    mysql_result($result,0,"emp_auth.user_id");
                else
                    return 
    false;
            }
        } 
    i tried changing:
    PHP Code:
    if ($this->is_checked($user) && $this->is_checked($user) ) 
    into
    PHP Code:
    if ($this->is_checked($user) && $this->is_checked($pass) ) 
    but no luck
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Supplied Argument not valid

    you need to check if the result is valid first.

    Code:
    if (!$result) {
         die(mysql_error()); 
    }
    put this little code snippet right above your call to mysql_num_rows(). Now, if there is an error, php will stop (die) and print out the mysql error so you can go back and fix it.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: Supplied Argument not valid

    tnx. i we tried this one :

    PHP Code:
     or die('Query failed: ' mysql_error() . "<br />\n$query"); 
    The problem was the, columns were interchange... that's why the query did not work.
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Supplied Argument not valid

    You had the hard part right
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: Supplied Argument not valid

    This time it's my code that is not working. i don't know why:
    It gives the error:
    Warning: Invalid argument supplied for foreach() in D:\********\blablabla.php on line 134

    PHP Code:
    function browsing($album_array$user)
    {
        
    $output;
        
        if( 
    is_valid($user) )
        {
            
    $output '<p>';
            if ( !isset(
    $album_array) ||  count($album_array) == 0)
                
    $output .= $user ' currently has no albums.';
            else if ( 
    count($album_array) == )
                
    $output .= $user ' currently has 1 album.';
            else
                
    $output .= $user ' currently has ' count($album_array) . ' albums.';
            
    $output .= '</p>';

            
    $i 0;
            if( isset(
    $album_array) )
            {
                
    $output .= '<ul class="albums_list">';
                foreach( 
    $album_array as $record )            //line 134
                
    {
                    
    $output .= '<li>';
                    
    $output .= '<a class="link_browse_album" href="index.php?view=browse_alb&amp;album=' $record['album_id'] . '&amp;user=' $user '">'
                        
    $record['title'] . '</a>';
                    
    $output .= '</li>';

                    
    $i++;
                }
                
    $output .= '</ul>';
            }

            return 
    $output;
        }

    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Supplied Argument not valid

    You might want to put some error checking to make sure that $album_array is indeed an array using is_array(). You should also make sure that the foreach() cannot execute if count($album_array) is 0.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: Supplied Argument not valid

    yes it helps by using is_array. but i can't figure out how to make sure foreach cannot execute if count($album_array) is 0

    by the way do u have a YM account?
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  8. #8
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Supplied Argument not valid

    I do, same as my forum name. I'm not on until after 6pm CST.

    Code:
     if( isset($album_array) && count($album_array) > 0) // ** changed this line
            {
                $output .= '<ul class="albums_list">';
                foreach( $album_array as $record )            //line 134
                {
                    $output .= '<li>';
                    $output .= '<a class="link_browse_album" href="index.php?view=browse_alb&amp;album=' . $record['album_id'] . '&amp;user=' . $user . '">'
                        . $record['title'] . '</a>';
                    $output .= '</li>';
    
                    $i++;
                }
                $output .= '</ul>';
            }
    Last edited by garrettroyce; 05-21-2009 at 01:06 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread

Similar Threads

  1. I deleted .htaccess file by mistake!
    By N|me F A T A L 1 T Y in forum Free Hosting
    Replies: 9
    Last Post: 04-06-2009, 09:34 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  4. GeIP Script Help
    By cybahq in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 07-30-2008, 06:19 AM
  5. GeIP Script Help
    By cybahq in forum Free Hosting
    Replies: 4
    Last Post: 07-30-2008, 05:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers