tags:

views:

329

answers:

1

I get: "Resource id #8 Warning: mysql_fetch_array() expects parameter 1 to be resource, string given"

Heres the code:

$sql="SELECT password FROM user WHERE userid=$userid";    
echo $password=mysql_query($sql);

while($row = mysql_fetch_array($password)) {
    $password = $row['password'];
}   

Any ideas?

A: 

You are overwriting $password in the loop:

while($row = mysql_fetch_array($password)) {  <-------- $password as resource
    $password = $row['password'];             <-------- $password as string
} 

this should work:

 while($row = mysql_fetch_array($password)) {
    $password_record = $row['password'];
} 
Pekka
Doh - Thanks.Strange as I reused that code for something else and it didn't complain. :-)
Damien
@Damien that loop probably had only one record :)
Pekka