tags:

views:

17

answers:

3

Can anyone tell me why I am recieving these errors when I do this???

   Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\login\index.php on line 63

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\login\index.php on line 65

When I do this::

    $sql="SELECT id FROM users WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
+1  A: 

You probably have an error making your query. Try

$result=mysql_query($sql) or die(mysql_error());
Johan
+1  A: 

From documentation of mysql_query:

Return Values: For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

It seems that your mySQL query contains some sort of error (did you escape the strings you're putting in?), therefore $result is FALSE, therefore the warnings. Try this:

$result = mysql_query($sql);
if (!$result) {
    echo mysql_error();
}
Piskvor
A: 

Mysql_query returns false when the executed query contained errors. Try using mysql_error to find out what went wrong.

Mysql_num_rows and mysql_fetch_array both expect the result of a valid query.

jpluijmers