tags:

views:

58

answers:

2

I am getting this warning:

Warning: mysql_num_rows() expects parameter 1 to be resource

On this script:

if (isset($_POST['submit'])){  
 change_db($realm_DB);  
 $loginusername = "$acc_name";  
 $loginpass = $_POST['password'];  
 $sha_pass_hash = sha1(strtoupper($loginusername) . ":" . strtoupper($loginpass));  
 $qry=mysql_query("UPDATE `$realm_DB`.`account` SET `sha_pass_hash`='$sha_pass_hash', `v`='', `s`='', WHERE (`username`='$loginusername');");  
 if (mysql_num_rows($qry) == 1){  
?>  
  < script type="text/javascript" >  
  {  
   alert("Successfully changed password!");  
  }  
  < /script>  
< ?php  
}  
}  
?> 

My code otherwise works but is the warning somehow hideable? It appears right in middle of my website -_-

+3  A: 

http://php.net/mysql_query

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

$qry at this point is either true or false, but it's not a resource that you can feed into mysql_num_rows.

deceze
+2  A: 

Use mysql_affected_rows() if you want to know how many rows were affected by an INSERT, UPDATE, REPLACE or DELETE query.

EDIT

And get rid of the spurious , before the WHERE in your UPDATE statement.... otherwise it will always return an error... I've no idea how you can claim it's working at present

Mark Baker