Supplied Argument not valid

zyreena

New Member
Messages
57
Reaction score
0
Points
0
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 :biggrin:)

PHP:
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:
if ($this->is_checked($user) && $this->is_checked($user) )
into
PHP:
if ($this->is_checked($user) && $this->is_checked($pass) )
but no luck
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
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.
 

zyreena

New Member
Messages
57
Reaction score
0
Points
0
tnx. i we tried this one :

PHP:
 or die('Query failed: ' . mysql_error() . "<br />\n$query");

The problem was the, columns were interchange... that's why the query did not work.
 

zyreena

New Member
Messages
57
Reaction score
0
Points
0
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:
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) == 1 )
            $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;
    }
}
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
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.
 

zyreena

New Member
Messages
57
Reaction score
0
Points
0
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?
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
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:
Top